#include <bits/stdc++.h>
using namespace std;
int n;
int a[100000];
int tree[20][1 << 18];
bool lazy[20][1 << 18];
void build(int l, int r, int i) {
  if (l == r) {
    for (int b = 0; b < 20; ++b) tree[b][i] = (a[l] >> b) & 1;
    return;
  }
  int mid = (l + r) >> 1, li = i << 1, ri = li + 1;
  build(l, mid, li);
  build(mid + 1, r, ri);
  for (int b = 0; b < 20; ++b) tree[b][i] = tree[b][li] + tree[b][ri];
}
void update(int l, int r, int s, int t, int x, int i) {
  if (l > t || r < s) return;
  if (l >= s && r <= t) {
    for (int b = 0; b < 20; ++b)
      if ((x >> b) & 1) {
        tree[b][i] = r - l + 1 - tree[b][i];
        lazy[b][i] ^= 1;
      }
    return;
  }
  int mid = (l + r) >> 1, li = i << 1, ri = li + 1;
  for (int b = 0; b < 20; ++b) {
    if (lazy[b][i]) {
      tree[b][li] = mid - l + 1 - tree[b][li];
      lazy[b][li] ^= 1;
      tree[b][ri] = r - mid - tree[b][ri];
      lazy[b][ri] ^= 1;
      lazy[b][i] = 0;
    }
  }
  update(l, mid, s, t, x, li);
  update(mid + 1, r, s, t, x, ri);
  for (int b = 0; b < 20; ++b) tree[b][i] = tree[b][li] + tree[b][ri];
}
long long query(int l, int r, int s, int t, int i) {
  if (l > t || r < s) return 0;
  if (l >= s && r <= t) {
    long long ret = 0;
    for (int b = 0; b < 20; ++b) ret += (1LL << b) * tree[b][i];
    return ret;
  }
  int mid = (l + r) >> 1, li = i << 1, ri = li + 1;
  for (int b = 0; b < 20; ++b) {
    if (lazy[b][i]) {
      tree[b][li] = mid - l + 1 - tree[b][li];
      lazy[b][li] ^= 1;
      tree[b][ri] = r - mid - tree[b][ri];
      lazy[b][ri] ^= 1;
      lazy[b][i] = 0;
    }
  }
  return query(l, mid, s, t, li) + query(mid + 1, r, s, t, ri);
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  build(0, n - 1, 1);
  int m;
  scanf("%d", &m);
  while (m--) {
    int t;
    scanf("%d", &t);
    int l, r;
    if (t == 1) {
      scanf("%d %d", &l, &r);
      --l;
      --r;
      printf("%I64d\n", query(0, n - 1, l, r, 1));
    } else {
      scanf("%d %d %d", &l, &r, &t);
      --l;
      --r;
      update(0, n - 1, l, r, t, 1);
    }
  }
  return 0;
}
