#include <bits/stdc++.h>
using namespace std;
int tre[500000][20];
bool lazy[500000][20];
bool a[500000][20];
void build(long long nd, long long tl, long long tr, long long i) {
  if (tl == tr) {
    tre[nd][i] = a[tl][i];
    return;
  }
  long long mid = (tl + tr) / 2;
  build(2 * nd + 1, tl, mid, i);
  build(2 * nd + 2, mid + 1, tr, i);
  tre[nd][i] = tre[2 * nd + 1][i] + tre[2 * nd + 2][i];
}
void update(long long nd, long long tl, long long tr, long long l, long long r,
            long long i) {
  if (lazy[nd][i]) {
    tre[nd][i] = tr - tl + 1 - tre[nd][i];
    if (tl != tr) {
      lazy[2 * nd + 1][i] ^= 1;
      lazy[2 * nd + 2][i] ^= 1;
    }
    lazy[nd][i] = 0;
  }
  if (l > tr || r < tl) return;
  if (tl >= l && tr <= r) {
    tre[nd][i] = tr - tl + 1 - tre[nd][i];
    if (tl != tr) {
      lazy[2 * nd + 1][i] ^= 1;
      lazy[2 * nd + 2][i] ^= 1;
    }
    return;
  }
  long long mid = (tl + tr) / 2;
  update(2 * nd + 1, tl, mid, l, r, i);
  update(2 * nd + 2, mid + 1, tr, l, r, i);
  tre[nd][i] = tre[2 * nd + 1][i] + tre[2 * nd + 2][i];
}
long long query(long long nd, long long tl, long long tr, long long l,
                long long r, long long i) {
  if (lazy[nd][i]) {
    tre[nd][i] = tr - tl + 1 - tre[nd][i];
    if (tl != tr) {
      lazy[2 * nd + 1][i] ^= 1;
      lazy[2 * nd + 2][i] ^= 1;
    }
    lazy[nd][i] = 0;
  }
  if (tl > r || tr < l) return 0;
  if (tl >= l && tr <= r) {
    return tre[nd][i];
  }
  long long mid = (tl + tr) / 2;
  return query(2 * nd + 1, tl, mid, l, r, i) +
         query(2 * nd + 2, mid + 1, tr, l, r, i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, j;
  cin >> n;
  for (i = 0; i < n; i++) {
    long long x;
    cin >> x;
    for (j = 0; j < 20; j++) {
      if (x % 2) a[i][j] = 1;
      x /= 2;
    }
  }
  for (i = 0; i < 20; i++) build(1, 0, n - 1, i);
  long long m;
  cin >> m;
  while (m--) {
    long long ch;
    cin >> ch;
    if (ch == 1) {
      long long l, r;
      cin >> l >> r;
      long long ans = 0;
      for (i = 0; i < 20; i++) {
        ans += pow(2, i) * query(1, 0, n - 1, l - 1, r - 1, i);
      }
      cout << ans << "\n";
    } else {
      long long l, r, x;
      cin >> l >> r >> x;
      for (i = 0; i < 20; i++) {
        if (x % 2) update(1, 0, n - 1, l - 1, r - 1, i);
        x /= 2;
      }
    }
  }
  return 0;
}
