#include <bits/stdc++.h>
using namespace std;
struct forZ {
  vector<long long int> BIT[20];
  int prev[200000];
  int N, Z;
  int maxsZ;
  void init(int _n, int _Z) {
    N = _n;
    Z = (_Z - 1) * 2;
    maxsZ = (N + Z) / Z + 10;
    for (int i = 0; i <= 12; i++) BIT[i].resize(10 + (N + Z) / Z);
  }
  void U(int loc, int val) {
    int i;
    int rem = loc % Z;
    loc /= Z;
    loc += 3;
    for (i = loc; i < maxsZ; i += (i & -i)) BIT[rem][i] += val;
  }
  long long int Q(int loc) {
    if (loc < 0) return 0;
    int i;
    long long int ret = 0;
    int rem = loc % Z;
    loc /= Z;
    loc += 3;
    for (i = loc; i > 0; i -= (i & -i)) ret += BIT[rem][i];
    return ret;
  }
  void upd(int loc, int ele) {
    U(loc, ele - prev[loc]);
    prev[loc] = ele;
  }
  long long int lastmul(long long int a, long long int b) {
    long long int mul = a / Z;
    mul *= Z;
    mul += b;
    mul += Z;
    while (mul >= a) mul -= Z;
    return mul;
  }
  long long int query(int lft, int rgt) {
    long long int ans = 0;
    int i;
    long long int cur = 1;
    for (i = 0; i < Z / 2; i++)
      ans += cur++ * (Q(lastmul(rgt + 1, (i + lft) % Z)) -
                      Q(lastmul(lft, (i + lft) % Z)));
    for (i = Z / 2; i < Z; i++) {
      ans += cur-- * (Q(lastmul(rgt + 1, (i + lft) % Z)) -
                      Q(lastmul(lft, (i + lft) % Z)));
    }
    return ans;
  }
};
int n, i;
forZ dss[7];
int main() {
  int x, j;
  cin >> n;
  for (i = 2; i <= 6; i++) {
    dss[i].init(n, i);
  }
  for (i = 0; i < n; i++) {
    cin >> x;
    for (j = 2; j <= 6; j++) dss[j].upd(i, x);
  }
  int m, l, r, z, tp;
  cin >> m;
  while (m--) {
    cin >> tp;
    if (tp == 2) {
      cin >> l >> r >> z;
      l--;
      r--;
      cout << dss[z].query(l, r) << endl;
    } else {
      cin >> l >> z;
      l--;
      for (i = 2; i <= 6; i++) dss[i].upd(l, z);
    }
  }
  return 0;
}
