#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005, LOG = 20;
int tree[LOG][4 * MAXN], lazy[LOG][4 * MAXN], A[MAXN];
void updatenode(int id, int now, int L, int R) {
  tree[id][now] = (R - L + 1) - tree[id][now];
  lazy[id][now] ^= 1;
}
void pushdown(int id, int now, int L, int R) {
  if (lazy[id][now] == 0) return;
  int mid = (L + R) / 2;
  updatenode(id, 2 * now, L, mid);
  updatenode(id, 2 * now + 1, mid + 1, R);
  lazy[id][now] = 0;
}
void build(int id, int now, int L, int R) {
  if (L == R) {
    tree[id][now] = (((1 << id) & A[L]) > 0);
    return;
  }
  int mid = (L + R) / 2;
  build(id, 2 * now, L, mid);
  build(id, 2 * now + 1, mid + 1, R);
  tree[id][now] = tree[id][2 * now] + tree[id][2 * now + 1];
}
void update(int id, int now, int L, int R, int x, int y) {
  if (L >= x && R <= y) {
    updatenode(id, now, L, R);
    return;
  }
  if (L > y || R < x) return;
  pushdown(id, now, L, R);
  int mid = (L + R) / 2;
  update(id, 2 * now, L, mid, x, y);
  update(id, 2 * now + 1, mid + 1, R, x, y);
  tree[id][now] = tree[id][2 * now] + tree[id][2 * now + 1];
}
int query(int id, int now, int L, int R, int x, int y) {
  if (L >= x && R <= y) return tree[id][now];
  if (L > y || R < x) return 0;
  pushdown(id, now, L, R);
  int mid = (L + R) / 2;
  return query(id, 2 * now, L, mid, x, y) +
         query(id, 2 * now + 1, mid + 1, R, x, y);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, q, op, l, r, X;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < LOG; i++) build(i, 1, 1, n);
  cin >> q;
  while (q--) {
    cin >> op >> l >> r;
    if (op == 1) {
      long long ans = 0;
      for (int i = 0; i < LOG; i++) {
        ans += ((1LL << i) * query(i, 1, 1, n, l, r));
      }
      cout << ans << '\n';
    } else {
      cin >> X;
      for (int i = 0; i < LOG; i++) {
        if (X & (1 << i)) {
          update(i, 1, 1, n, l, r);
        }
      }
    }
  }
  return 0;
}
