#include <bits/stdc++.h>
using namespace std;
const int limite = 1000000;
const int limitebis = 200000;
long long int suma[30][limite];
int seq[30][limitebis];
int numseq;
int primero, tope;
int n, m;
long long int a[limitebis];
int comienza[7];
void inserta(int pos, long long int val) {
  int posa = pos;
  a[posa] = val;
  pos += primero;
  for (int i = 0; i < numseq; i++) suma[i][pos] = seq[i][posa] * a[posa];
  while (pos > 1) {
    pos /= 2;
    for (int i = 0; i < numseq; i++)
      suma[i][pos] = suma[i][2 * pos] + suma[i][2 * pos + 1];
  }
}
long long int sumaantes(int pos, int iseq) {
  pos += primero;
  long long int s = suma[iseq][pos];
  while (pos > 1) {
    if (pos % 2 == 1) s += suma[iseq][pos - 1];
    pos /= 2;
  }
  return s;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  {
    numseq = 0;
    for (int i = 2; i <= 6; i++) {
      comienza[i] = numseq;
      int sig = 1;
      seq[numseq][0] = 1;
      for (int j = 1; j < limitebis; j++) {
        seq[numseq][j] = seq[numseq][j - 1] + sig;
        if (seq[numseq][j] == i)
          sig = -1;
        else if (seq[numseq][j] == 1)
          sig = 1;
      }
      for (int k = 1; k < 2 * i - 2; k++)
        for (int j = 0; j < limitebis; j++)
          seq[numseq + k][j] =
              seq[numseq + k - 1][(j - 1 + 2 * i - 2) % limitebis];
      numseq += 2 * i - 2;
    }
  }
  {
    int nn = n;
    primero = 1;
    while (nn > 0) {
      nn /= 2;
      primero *= 2;
    }
    tope = 2 * primero;
    for (int i = 0; i < n; i++) inserta(i, a[i]);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int p, val;
      cin >> p >> val;
      p--;
      inserta(p, val);
    } else {
      int l, r, z;
      cin >> l >> r >> z;
      l--;
      r--;
      int iseq = comienza[z] + l % (2 * z - 2);
      long long int s = sumaantes(r, iseq);
      if (l > 0) s -= sumaantes(l - 1, iseq);
      cout << s << endl;
    }
  }
}
