#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9;
const int mod = (int)1e9 + 7;
const double PI = acos(-1.0);
const int MAX = (1 << 18);
const int S = 21;
int n, arr[MAX];
int st[S][MAX];
int lz[S][MAX];
void push_down(int b, int node, int ns, int ne) {
  if (!lz[b][node]) return;
  st[b][node] = (ne - ns + 1) - st[b][node];
  lz[b][node] = 0;
  if (ns != ne) {
    lz[b][2 * node + 1] ^= 1;
    lz[b][2 * node + 2] ^= 1;
  }
}
void flip(int b, int node, int ns, int ne, int qs, int qe) {
  push_down(b, node, ns, ne);
  if (ns > qe || ne < qs) return;
  if (ns >= qs && ne <= qe) {
    st[b][node] = (ne - ns + 1) - st[b][node];
    if (ns != ne) {
      lz[b][2 * node + 1] ^= 1;
      lz[b][2 * node + 2] ^= 1;
    }
    return;
  }
  int mid = ns + (ne - ns) / 2;
  flip(b, 2 * node + 1, ns, mid, qs, qe);
  flip(b, 2 * node + 2, mid + 1, ne, qs, qe);
  st[b][node] = st[b][2 * node + 1] + st[b][2 * node + 2];
}
int query(int b, int node, int ns, int ne, int qs, int qe) {
  if (ns > qe || ne < qs) return 0;
  push_down(b, node, ns, ne);
  if (ns >= qs && ne <= qe) return st[b][node];
  int mid = ns + (ne - ns) / 2;
  return query(b, 2 * node + 1, ns, mid, qs, qe) +
         query(b, 2 * node + 2, mid + 1, ne, qs, qe);
}
long long get(int l, int r) {
  long long res = 0;
  for (int j = 0; j < 20; j++) res += (1LL << j) * query(j, 0, 0, n - 1, l, r);
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &arr[i]);
    for (int j = 0; j < 20; j++)
      if (arr[i] & (1 << j)) flip(j, 0, 0, n - 1, i, i);
  }
  int q;
  scanf("%d", &q);
  while (q--) {
    int op, l, r, x;
    scanf("%d", &op);
    if (op == 1) {
      scanf("%d%d", &l, &r);
      printf("%I64d\n", get(--l, --r));
    } else {
      scanf("%d%d%d", &l, &r, &x);
      --l, --r;
      for (int j = 0; j < 20; j++)
        if (x & (1 << j)) flip(j, 0, 0, n - 1, l, r);
    }
  }
  return 0;
}
