#include <bits/stdc++.h>
using namespace std;
const int OO = 2e9;
const int MOD = 1e9 + 7;
const double Pi = 3.141592653589793;
const int N = 1e5 + 5;
struct data {
  int l, r;
  long long s[7][12];
} IT[3 * N];
int a[N];
int n, q;
data combine(data a, data b) {
  data res;
  res.l = a.l;
  res.r = b.r;
  for (int z = (int)2; z <= (int)6; z++)
    for (int p = (int)1; p <= (int)2 * z - 2; p++)
      res.s[z][p] = 1LL * a.s[z][p] + b.s[z][(a.r - a.l + p) % (2 * z - 2) + 1];
  return res;
}
int S(int z, int i) {
  int l = 2 * (z - 1);
  if (i % l == 0) return 2;
  if (i % l <= z) return i % l;
  return 2 * z - (i % l);
}
void gen(int x, int l, int r) {
  if (l == r) {
    IT[x].l = l;
    IT[x].r = r;
    for (int z = (int)2; z <= (int)6; z++)
      for (int p = (int)1; p <= (int)2 * z - 2; p++)
        IT[x].s[z][p] = 1LL * a[l] * S(z, p);
    return;
  }
  int m = (l + r) >> 1;
  gen(x * 2, l, m);
  gen(x * 2 + 1, m + 1, r);
  IT[x] = combine(IT[x * 2], IT[x * 2 + 1]);
}
void update(int x, int l, int r, int P, int v) {
  if (l == r) {
    a[l] = v;
    for (int z = (int)2; z <= (int)6; z++)
      for (int p = (int)1; p <= (int)2 * z - 2; p++)
        IT[x].s[z][p] = 1LL * a[l] * S(z, p);
  } else {
    int m = (l + r) >> 1;
    if (P <= m)
      update(x * 2, l, m, P, v);
    else
      update(x * 2 + 1, m + 1, r, P, v);
    IT[x] = combine(IT[x * 2], IT[x * 2 + 1]);
  }
}
data query(int x, int l, int r, int L, int R) {
  if (L <= l && r <= R) return IT[x];
  int m = (l + r) >> 1;
  if (R <= m) return query(x * 2, l, m, L, R);
  if (m < L) return query(x * 2 + 1, m + 1, r, L, R);
  return combine(query(x * 2, l, m, L, R), query(x * 2 + 1, m + 1, r, L, R));
}
int main() {
  cin >> n;
  for (int i = (int)1; i <= (int)n; i++) scanf("%i", &a[i]);
  gen(1, 1, n);
  cin >> q;
  int t, x, y, z;
  while (q--) {
    scanf("%i%i%i", &t, &x, &y);
    if (t == 1)
      update(1, 1, n, x, y);
    else {
      scanf("%i", &z);
      data db = (query(1, 1, n, x, y));
      printf("%I64d\n", db.s[z][1]);
    }
  }
}
