#include <bits/stdc++.h>
using namespace std;
int n, a[100000 + 5], m, t, li, ri, x;
int st[20][400000 + 5];
bitset<400000 + 5> lazy[20];
void build(int p, int l, int r) {
  if (l == r) {
    for (int i = 0, _i = (20); i < _i; ++i) st[i][p] = (a[l] >> i) & 1;
    return;
  }
  build(p << 1, l, (l + r) >> 1);
  build(p << 1 | 1, ((l + r) >> 1) + 1, r);
  for (int i = 0, _i = (20); i < _i; ++i)
    st[i][p] = st[i][p << 1] + st[i][p << 1 | 1];
}
void update(int p, int l, int r, int i) {
  if (lazy[i][p]) {
    st[i][p] = r - l + 1 - st[i][p];
    if (l != r) {
      lazy[i].flip(p << 1);
      lazy[i].flip(p << 1 | 1);
    }
    lazy[i][p] = 0;
  }
  if (li > r || ri < l) return;
  if (li <= l && r <= ri) {
    st[i][p] = r - l + 1 - st[i][p];
    if (l != r) {
      lazy[i].flip(p << 1);
      lazy[i].flip(p << 1 | 1);
    }
    return;
  }
  update(p << 1, l, (l + r) >> 1, i);
  update(p << 1 | 1, ((l + r) >> 1) + 1, r, i);
  st[i][p] = st[i][p << 1] + st[i][p << 1 | 1];
}
int query(int p, int l, int r, int i) {
  if (lazy[i][p]) {
    st[i][p] = r - l + 1 - st[i][p];
    if (l != r) {
      lazy[i].flip(p << 1);
      lazy[i].flip(p << 1 | 1);
    }
    lazy[i][p] = 0;
  }
  if (li > r || ri < l) return 0;
  if (li <= l && r <= ri) return st[i][p];
  return query(p << 1, l, (l + r) >> 1, i) +
         query(p << 1 | 1, ((l + r) >> 1) + 1, r, i);
}
int main() {
  int t;
  scanf("%d", &n);
  for (int i = 0, _i = (n); i < _i; ++i) scanf("%d", a + i + 1);
  build(1, 1, n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &t);
    if (t - 1) {
      scanf("%d%d%d", &li, &ri, &x);
      for (int i = 0, _i = (20); i < _i; ++i)
        if (x & (1 << i)) update(1, 1, n, i);
    } else {
      scanf("%d%d", &li, &ri);
      long long ans = 0;
      for (int i = 0, _i = (20); i < _i; ++i)
        ans += (long long)query(1, 1, n, i) * (1L << i);
      printf("%I64d\n", ans);
    }
  }
}
