#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
long long tree[7][4 * N];
int tp[7][N];
int st[7][20];
int a[N];
int n, m;
long long ans;
void Read(int &x) {
  char c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  x = c - '0';
  while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0';
}
void Make(long long *t, int *a, int x, int l, int r) {
  if (l == r) {
    t[x] = a[l];
    return;
  }
  int mid = (l + r) >> 1;
  Make(t, a, x + x, l, mid);
  Make(t, a, x + x + 1, mid + 1, r);
  t[x] = t[x + x] + t[x + x + 1];
}
void Init() {
  Read(n);
  int temp;
  for (int i = 1; i <= n; i++) Read(a[i]);
  for (int i = 2; i <= 6; i++) {
    int temp = (i + i - 2);
    int tot = 0;
    for (int j = 1; j <= temp; j++) {
      st[i][j] = tot;
      for (int k = j; k <= n; k += temp) tp[i][++tot] = a[k];
    }
    Make(tree[i], tp[i], 1, 1, n);
  }
}
void Change(long long *t, int x, int l, int r, int pos, int value) {
  if (l > pos || r < pos) return;
  if (l == r) {
    t[x] = value;
    return;
  }
  int mid = (l + r) >> 1;
  Change(t, x + x, l, mid, pos, value);
  Change(t, x + x + 1, mid + 1, r, pos, value);
  t[x] = t[x + x] + t[x + x + 1];
}
void Find(long long *t, int x, int l, int r, int st, int en) {
  if (l > en || st > r) return;
  if (st <= l && r <= en) {
    ans += t[x];
    return;
  }
  int mid = (l + r) >> 1;
  Find(t, x + x, l, mid, st, en);
  Find(t, x + x + 1, mid + 1, r, st, en);
}
void Work() {
  Read(m);
  int t, x, y, z;
  for (int i = 1; i <= m; i++) {
    Read(t);
    if (t == 1) {
      Read(x);
      Read(y);
      a[x] = y;
      for (int j = 2; j <= 6; j++) {
        int temp = j + j - 2, tt = (x - 1) % temp + 1;
        Change(tree[j], 1, 1, n, st[j][tt] + (x - 1) / temp + 1, y);
      }
    } else {
      Read(x);
      Read(y);
      Read(z);
      int temp = z + z - 2, tt, J;
      long long sum = 0;
      for (int j = 1; j <= temp; j++) {
        J = (j + x - 2) % temp + 1;
        if (j > z) tt = z + z - j;
        if (j <= z) tt = j;
        if (j == temp) tt = 2;
        int S = (x - 1) / temp + 1, E = (y - 1) / temp + 1;
        if ((S - 1) * temp + J < x) S++;
        if ((E - 1) * temp + J > y) E--;
        ans = 0;
        Find(tree[z], 1, 1, n, st[z][J] + S, st[z][J] + E);
        sum += tt * ans;
      }
      printf("%I64d\n", sum);
    }
  }
}
int main() {
  Init();
  Work();
  return 0;
}
