The court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, like the Fibonacci sequence, and his function, like the Euler's totient function.

The Zigag's sequence with the zigzag factor z is an infinite sequence Siz (i ≥ 1; z ≥ 2), that is determined as follows:

  * Siz = 2, when <image>; 
  * <image>, when <image>; 
  * <image>, when <image>. 



Operation <image> means taking the remainder from dividing number x by number y. For example, the beginning of sequence Si3 (zigzag factor 3) looks as follows: 1, 2, 3, 2, 1, 2, 3, 2, 1.

Let's assume that we are given an array a, consisting of n integers. Let's define element number i (1 ≤ i ≤ n) of the array as ai. The Zigzag function is function <image>, where l, r, z satisfy the inequalities 1 ≤ l ≤ r ≤ n, z ≥ 2.

To become better acquainted with the Zigzag sequence and the Zigzag function, the wizard offers you to implement the following operations on the given array a.

  1. The assignment operation. The operation parameters are (p, v). The operation denotes assigning value v to the p-th array element. After the operation is applied, the value of the array element ap equals v. 
  2. The Zigzag operation. The operation parameters are (l, r, z). The operation denotes calculating the Zigzag function Z(l, r, z). 



Explore the magical powers of zigzags, implement the described operations.

Input

The first line contains integer n (1 ≤ n ≤ 105) — The number of elements in array a. The second line contains n space-separated integers: a1, a2, ..., an (1 ≤ ai ≤ 109) — the elements of the array. 

The third line contains integer m (1 ≤ m ≤ 105) — the number of operations. Next m lines contain the operations' descriptions. An operation's description starts with integer ti (1 ≤ ti ≤ 2) — the operation type. 

  * If ti = 1 (assignment operation), then on the line follow two space-separated integers: pi, vi (1 ≤ pi ≤ n; 1 ≤ vi ≤ 109) — the parameters of the assigning operation. 
  * If ti = 2 (Zigzag operation), then on the line follow three space-separated integers: li, ri, zi (1 ≤ li ≤ ri ≤ n; 2 ≤ zi ≤ 6) — the parameters of the Zigzag operation. 



You should execute the operations in the order, in which they are given in the input.

Output

For each Zigzag operation print the calculated value of the Zigzag function on a single line. Print the values for Zigzag functions in the order, in which they are given in the input.

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

Examples

Input

5
2 3 1 5 5
4
2 2 3 2
2 1 5 3
1 3 5
2 1 5 3


Output

5
26
38

Note

Explanation of the sample test: 

  * Result of the first operation is Z(2, 3, 2) = 3·1 + 1·2 = 5. 
  * Result of the second operation is Z(1, 5, 3) = 2·1 + 3·2 + 1·3 + 5·2 + 5·1 = 26. 
  * After the third operation array a is equal to 2, 3, 5, 5, 5. 
  * Result of the forth operation is Z(1, 5, 3) = 2·1 + 3·2 + 5·3 + 5·2 + 5·1 = 38. 
#include <bits/stdc++.h>
using namespace std;
template <class T>
void PA(T x[], int n) {
  for (int i = 0; i < n; ++i) cout << x[i] << " ";
  cout << endl;
}
const int N = 100000;
int z[5][20];
int a[N];
int len[5];
struct Seg {
  int l, r, lc, rc;
  long long s[5][10];
} seg[N * 2];
int segn;
void update(Seg &ns, Seg &ls, Seg &rs) {
  for (int n_ = (5), z = 0; z < n_; ++z)
    for (int n_ = (len[z]), o = 0; o < n_; ++o) {
      ns.s[z][o] = ls.s[z][o] + rs.s[z][o];
    }
}
int seg_init(int l, int r) {
  int p = segn++;
  Seg &ns = seg[p];
  ns.l = l, ns.r = r;
  if (l == r) {
    for (int n_ = (5), zz = 0; zz < n_; ++zz)
      for (int n_ = (len[zz]), o = 0; o < n_; ++o)
        ns.s[zz][o] = (long long)z[zz][(l + o) % len[zz]] * a[l];
    return p;
  }
  int mid = (l + r) / 2;
  ns.lc = seg_init(l, mid);
  ns.rc = seg_init(mid + 1, r);
  update(ns, seg[ns.lc], seg[ns.rc]);
  return p;
}
void seg_ins(int p, int x, int v) {
  Seg &ns = seg[p];
  if (ns.l == ns.r) {
    for (int n_ = (5), zz = 0; zz < n_; ++zz)
      for (int n_ = (len[zz]), o = 0; o < n_; ++o)
        ns.s[zz][o] = (long long)z[zz][(ns.l + o) % len[zz]] * v;
    return;
  }
  int mid = (ns.l + ns.r) / 2;
  if (x <= mid)
    seg_ins(ns.lc, x, v);
  else
    seg_ins(ns.rc, x, v);
  update(ns, seg[ns.lc], seg[ns.rc]);
}
long long seg_find(int p, int l, int r, int zz, int o) {
  Seg &ns = seg[p];
  if (l <= ns.l && ns.r <= r) {
    return ns.s[zz][o];
  }
  int mid = (ns.l + ns.r) / 2;
  long long ret = 0;
  if (l <= mid) ret += seg_find(ns.lc, l, r, zz, o);
  if (r > mid) ret += seg_find(ns.rc, l, r, zz, o);
  return ret;
}
int main(int argc, char *argv[]) {
  for (int n_ = (5), dz = 0; dz < n_; ++dz)
    for (int n_ = (20), di = 0; di < n_; ++di) {
      int zz = dz + 2;
      int i = di + 1;
      int &ret = z[dz][di];
      if (i % (2 * (zz - 1)) == 0)
        ret = 2;
      else if (i % (int)(2 * (zz - 1)) <= zz)
        ret = i % (2 * (zz - 1));
      else
        ret = 2 * zz - i % (2 * (zz - 1));
    }
  for (int n_ = (5), zz = 0; zz < n_; ++zz) len[zz] = (zz + 1) * 2;
  int n;
  cin >> n;
  for (int n_ = (n), i = 0; i < n_; ++i) cin >> a[i];
  seg_init(0, n - 1);
  int m;
  cin >> m;
  while (m--) {
    int t;
    cin >> t;
    if (t == 1) {
      int p, v;
      cin >> p >> v;
      p--;
      seg_ins(0, p, v);
    } else {
      int l, r, z;
      cin >> l >> r >> z;
      l--, r--, z -= 2;
      long long ret = seg_find(0, l, r, z, (len[z] - l % len[z]) % len[z]);
      cout << ret << endl;
    }
  }
  return 0;
}
