#include <bits/stdc++.h>
using namespace std;
struct Node {
  long long bit[2][22];
  Node() {
    for (long long i = 0; i < 22; i++) {
      bit[0][i] = 0;
      bit[1][i] = 0;
    }
  }
} node[400010];
long long n, m, t, l, r, x, a[100010], lazy[800010];
void build(long long p, long long l, long long r) {
  if (l == r) {
    for (long long i = 0; i < 21; i++) {
      if (a[l] & (1 << i))
        node[p].bit[1][i] += 1;
      else
        node[p].bit[0][i] += 1;
    }
  } else {
    build(2 * p, l, (l + r) / 2);
    build(2 * p + 1, (l + r) / 2 + 1, r);
    for (long long i = 0; i < 21; i++) {
      node[p].bit[0][i] = node[2 * p].bit[0][i] + node[2 * p + 1].bit[0][i];
      node[p].bit[1][i] = node[2 * p].bit[1][i] + node[2 * p + 1].bit[1][i];
    }
  }
}
long long sum(long long p, long long l, long long r, long long L, long long R) {
  if (lazy[p] != 0) {
    for (long long i = 0; i < 21; i++) {
      if ((1 << i) & lazy[p]) swap(node[p].bit[0][i], node[p].bit[1][i]);
    }
    lazy[2 * p] ^= lazy[p];
    lazy[2 * p + 1] ^= lazy[p];
    lazy[p] = 0;
  }
  if (l > r || l > R || r < L) return 0;
  if (l >= L && r <= R) {
    vector<long long> bits;
    bits.assign(55, 0);
    for (long long i = 0; i < 21; i++) {
      bits[i] = node[p].bit[1][i];
    }
    for (long long i = 0; i < 55; i++) {
      if (bits[i] & 1) {
        bits[i + 1] += (bits[i] - 1) / 2;
        bits[i] = 1;
      } else {
        bits[i + 1] += (bits[i] / 2);
        bits[i] = 0;
      }
    }
    long long res = 0;
    for (long long i = 0; i < 55; i++) {
      if (!bits[i]) continue;
      res += (1LL << i);
    }
    return res;
  }
  return sum(2 * p, l, (l + r) / 2, L, R) +
         sum(2 * p + 1, (l + r) / 2 + 1, r, L, R);
}
void update(long long p, long long l, long long r, long long L, long long R,
            long long x) {
  if (lazy[p] != 0) {
    for (long long i = 0; i < 21; i++) {
      if ((1 << i) & lazy[p]) swap(node[p].bit[0][i], node[p].bit[1][i]);
    }
    lazy[2 * p] ^= lazy[p];
    lazy[2 * p + 1] ^= lazy[p];
    lazy[p] = 0;
  }
  if (l > r || l > R || r < L) return;
  if (l >= L && r <= R) {
    for (long long i = 0; i < 21; i++) {
      if ((1 << i) & x) swap(node[p].bit[0][i], node[p].bit[1][i]);
    }
    lazy[2 * p] ^= x;
    lazy[2 * p + 1] ^= x;
    return;
  }
  update(2 * p, l, (l + r) / 2, L, R, x);
  update(2 * p + 1, (l + r) / 2 + 1, r, L, R, x);
  for (long long i = 0; i < 21; i++) {
    node[p].bit[0][i] = node[2 * p].bit[0][i] + node[2 * p + 1].bit[0][i];
    node[p].bit[1][i] = node[2 * p].bit[1][i] + node[2 * p + 1].bit[1][i];
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  build(1, 0, n - 1);
  cin >> m;
  while (m--) {
    cin >> t >> l >> r;
    l -= 1;
    r -= 1;
    if (t == 1) {
      cout << sum(1, 0, n - 1, l, r) << endl;
    } else {
      cin >> x;
      update(1, 0, n - 1, l, r, x);
    }
  }
  return 0;
}
