#include <bits/stdc++.h>
using namespace std;
const char al[100] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                      'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                      'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
vector<vector<long long int> > go(7);
vector<vector<vector<long long int> > > tree(5);
vector<vector<vector<long long int> > > values(5);
vector<long long int> my;
void inc(long long int i, long long int delta, long long int id,
         long long int mod) {
  for (; i < tree[id][mod].size(); i = (i | (i + 1))) tree[id][mod][i] += delta;
}
void init(long long int id, long long int mod) {
  long long int n = go[id].size();
  for (long long int i = 0; i < my.size(); i++) {
    values[id][mod][i] = my[i] * go[id][(i + mod) % n];
    inc(i, my[i] * go[id][(i + mod) % n], id, mod);
  }
}
long long int sum(long long int r, long long int id, long long int mod) {
  long long int result = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) result += tree[id][mod][r];
  return result;
}
long long int sum(long long int l, long long int r, long long int id,
                  long long int mod) {
  return sum(r, id, mod) - sum(l - 1, id, mod);
}
int main() {
  long long int pp;
  for (long long int i = 2; i <= 6; i++) {
    for (long long int j = 0; j < 2 * (i - 1); j++) {
      if ((j + 1) % (2 * (i - 1)) == 0)
        go[i - 2].push_back(2);
      else if ((j + 1) % (2 * (i - 1)) <= i)
        go[i - 2].push_back((j + 1) % (2 * (i - 1)));
      else
        go[i - 2].push_back(2 * i - (j + 1) % (2 * (i - 1)));
    }
  }
  cin >> pp;
  for (long long int i = 0; i < pp; i++) {
    long long int x;
    cin >> x;
    my.push_back(x);
  }
  for (long long int i = 0; i < 5; i++)
    tree[i].resize(go[i].size(), vector<long long int>(my.size(), 0));
  for (long long int i = 0; i < 5; i++)
    values[i].resize(go[i].size(), vector<long long int>(my.size(), 0));
  for (long long int i = 0; i < 5; i++) {
    for (long long int j = 0; j < go[i].size(); j++) init(i, j);
  }
  long long int m;
  cin >> m;
  long long int x, y, z, p;
  for (long long int i = 0; i < m; i++) {
    z = 0;
    cin >> p;
    if (p == 2)
      cin >> x >> y >> z;
    else
      cin >> x >> y;
    x--;
    y--;
    if (p == 2) {
      long long int to = x % go[z - 2].size();
      long long int temp;
      if (to != 0)
        temp = go[z - 2].size() - to;
      else
        temp = 0;
      cout << sum(x, y, z - 2, temp) << endl;
    } else {
      y++;
      long long int delta;
      for (long long int j = 0; j < 5; j++)
        for (long long int k = 0; k < go[j].size(); k++) {
          delta = y * go[j][(x + k) % go[j].size()] - values[j][k][x];
          values[j][k][x] += delta;
          inc(x, delta, j, k);
        }
    }
  }
};
