#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[100000];
int seg[20][1 << 18];
int ex[20][1 << 18];
void initSeg() {
  m = 1;
  while (m < n) m <<= 1;
  for (int k = 0; k < 20; k++) {
    for (int i = 0; i < n; i++) {
      if (a[i] >> k & 1) seg[k][m - 1 + i] = 1;
    }
    for (int i = m - 2; i >= 0; i--)
      seg[k][i] = seg[k][2 * i + 1] + seg[k][2 * i + 2];
  }
}
int query(int pos, int k, int l, int r, int a, int b) {
  if (a >= r || b <= l) return 0;
  if (a <= l && r <= b) return seg[pos][k];
  int c = (l + r) >> 1;
  int ret =
      query(pos, 2 * k + 1, l, c, a, b) + query(pos, 2 * k + 2, c, r, a, b);
  int span = min(r, b) - max(a, l);
  return ex[pos][k] == 0 ? ret : span - ret;
}
void flip(int pos, int k, int l, int r, int a, int b) {
  if (r <= a || b <= l) return;
  if (a <= l && r <= b) {
    ex[pos][k] ^= 1;
    seg[pos][k] = r - l - seg[pos][k];
  } else {
    int c = (l + r) >> 1;
    flip(pos, 2 * k + 1, l, c, a, b);
    flip(pos, 2 * k + 2, c, r, a, b);
    seg[pos][k] = seg[pos][2 * k + 1] + seg[pos][2 * k + 2];
    if (ex[pos][k]) seg[pos][k] = r - l - seg[pos][k];
  }
}
long long getSum(int l, int r) {
  long long ret = 0;
  for (int k = 0; k < 20; k++) {
    long long bc = query(k, 0, 0, m, l, r);
    ret += bc << k;
  }
  return ret;
}
void update(int l, int r, int x) {
  for (int k = 0; k < 20; k++) {
    if (x >> k & 1) flip(k, 0, 0, m, l, r);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  initSeg();
  int t;
  scanf("%d", &t);
  while (t--) {
    int type;
    scanf("%d", &type);
    int x, y, z;
    if (type == 1) {
      scanf("%d %d", &x, &y);
      --x, --y;
      cout << getSum(x, y + 1) << endl;
    } else {
      scanf("%d %d %d", &x, &y, &z);
      --x, --y;
      update(x, y + 1, z);
    }
  }
  return 0;
}
