#include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7, mo1 = 1234567891, mo2 = 1e9 + 123;
const int N = 1e3 + 12, Base = 131, M = 2e3 + 13;
template <class Tv>
Tv umin(Tv a, Tv b) {
  return a < b ? a : b;
}
template <class Tv>
Tv umax(Tv a, Tv b) {
  return a > b ? a : b;
}
int n, m, s[7][90];
int a[100005];
struct BIT {
  long long C[100005];
  long long& operator[](int alp) { return C[alp]; }
  int lowbit(int x) { return x & (-x); }
  void modify(int x, long long k) {
    for (int i = x; i <= n; i += lowbit(i)) C[i] += k;
  }
  void pri() {
    for (int i = 1; i <= n; i++) {
      cout << i << ':' << C[i] << endl;
    }
  }
  long long query(int x) {
    long long res = 0;
    for (int i = x; i; i -= lowbit(i)) {
      res += C[i];
    }
    return res;
  }
} bit[7][13];
int omi(int v, int z) {
  int alp = v % (2 * z - 2);
  if (!alp)
    return s[z][v] = 2, 2;
  else if (alp > z)
    return s[z][v] = 2 * z - alp, s[z][v];
  else
    return s[z][v] = alp, alp;
}
int pos(int i, int a, int b) {
  if (i == 1) return a;
  int tmp = i % b;
  tmp = !tmp ? b : tmp;
  if (a >= tmp)
    return a - tmp + 1;
  else
    return b + 1 - (tmp - a);
}
void change(int ip, int val) {
  for (int j = 2; j <= 6; j++)
    for (int k = 1; k <= 2 * (j - 1); k++)
      bit[j][pos(ip, k, 2 * j - 2)].modify(ip, 1ll * (val - a[ip]) * s[j][k]);
  a[ip] = val;
}
int main() {
  scanf("%d", &n);
  for (int j = 2; j <= 6; j++) {
    for (int k = 1; k <= 2 * (j - 1); k++) omi(k, j);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    for (int j = 2; j <= 6; j++) {
      for (int k = 1; k <= 2 * (j - 1); k++) {
        bit[j][pos(i, k, 2 * j - 2)].modify(i, 1ll * a[i] * s[j][k]);
      }
    }
  }
  scanf("%d", &m);
  while (m--) {
    int opt;
    scanf("%d", &opt);
    if (opt == 1) {
      int ip, v;
      scanf("%d%d", &ip, &v);
      change(ip, v);
    } else {
      int ql, qr, z;
      scanf("%d%d%d", &ql, &qr, &z);
      int ip = pos(ql, 1, (z - 1) * 2);
      long long res = bit[z][ip].query(qr) - bit[z][ip].query(ql - 1);
      printf("%lld\n", res);
    }
  }
  return 0;
}
