#include <bits/stdc++.h>
#define time() cerr << 1.0 * clock() / CLOCKS_PER_SEC << "s\n"
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a, _b = b; i <= _b; ++i)
#define FORD(i, a, b) for (int i = a, _b = b; i >= _b; --i)
#define FORLL(i, a, b) for (ll i = a, _b = b; i <= _b; ++i)
#define FORDLL(i, a, b) for (ll i = a, _b = b; i >= _b; --i)
#define all(x) x.begin(), x.end()
#define uni(x) sort(all(x)), x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define dbg(...) debug(#__VA_ARGS__, __VA_ARGS__)
template<typename T>
void __print_one(const char *&s, const T &x)
{
while (*s == ' ') ++s;
const char *p = s;
int bal = 0;
while (*s)
{
if (*s == '(') ++bal;
else if (*s == ')') --bal;
else if (*s == ',' && bal == 0) break;
++s;
}
cerr.write(p, s - p) << " = " << x;
if (*s == ',')
{
cerr << " , ";
++s;
}
}
template<typename... Args>
void debug(const char *s, Args... args)
{
cerr << "[ ";
int dummy[] = { 0 , (__print_one(s, args), 0)... };
(void)dummy;
cerr << " ]\n\n";
}
template<class X>
bool maximize(X &a, X b)
{
if (a < b)
{
a = b;
return true;
}
return false;
}
template<class X>
bool minimize(X &a, X b)
{
if (a > b)
{
a = b;
return true;
}
return false;
}
// -----------------------------------------------------------------
const int maxn = 1e5 + 3;
int n, q;
ll K, a[maxn];
struct FenTree
{
vector<ll> fw;
void init(int n)
{
fw.assign(n + 3, 0);
}
void upd(int pos, int val)
{
for (; pos < int(fw.size()); pos += pos & -pos)
fw[pos] += val;
}
ll get(int pos)
{
ll res = 0;
for (; pos; pos &= pos - 1)
res += fw[pos];
return res;
}
};
struct DSU
{
vector<int> e;
vector<int> maId;
void init(int n)
{
e.assign(n + 3, -1);
maId.assign(n + 3, -1);
}
int get(int u) { return e[u] < 0 ? u : e[u] = get(e[u]); }
bool unite(int u, int v)
{
u = get(u); v = get(v);
if (u == v) return false;
if (e[u] > e[v]) swap(u, v);
e[u] += e[v];
e[v] = u;
maId[u] = max(maId[u], maId[v]);
return true;
}
};
// -----------------------------------------------------------------
void solve()
{
cin >> n >> q >> K;
FenTree fw;
DSU dsu;
fw.init(n);
dsu.init(n);
FOR(i, 1, n)
{
cin >> a[i];
fw.upd(i, a[i]);
dsu.maId[i] = i;
}
while (q--)
{
int op; cin >> op;
if (op == 1)
{
int pos; ll val; cin >> pos >> val;
fw.upd(pos, val - a[pos]);
a[pos] = val;
}
else if (op == 2)
{
int l, r; cin >> l >> r;
if (K == 1) continue;
if (l > r) continue;
for (int i = dsu.maId[dsu.get(l)]; i <= r;)
{
fw.upd(i, a[i] / K - a[i]);
a[i] /= K;
if (a[i] == 0)
{
dsu.unite(i, i + 1);
i = dsu.maId[dsu.get(i)];
}
else
++i;
}
}
else
{
int l, r; cin >> l >> r;
if (l > r)
{
cout << "0\n";
continue;
}
cout << fw.get(r) - fw.get(l - 1) << '\n';
}
}
}
signed main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define TASK "test"
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
solve();
return 0;
}