#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 50;
const int M = 1e6;
const int oo = 1e9;
const int mod = 1e9 + 7;
long long a[N], b[400][21], u[400], c[N];
int main() {
  int n;
  cin >> n;
  int Z = sqrt(n) + 1;
  for (int i = 0; i < n; i++) cin >> a[i];
  int m;
  cin >> m;
  for (int i = 0; i < n; i++)
    for (int j = 0; j < 20; j++) b[i / Z][j] += ((a[i] >> j) & 1);
  for (int q = 0; q < m; q++) {
    int t, l, r;
    cin >> t >> l >> r;
    l--;
    r--;
    if (t == 1) {
      long long ans = 0;
      for (int i = l; i <= r; i++) {
        if (i % Z == 0 && i + Z - 1 <= r) {
          for (int j = 0; j < 20; j++) {
            ans += (1 << j) * 1ll * b[i / Z][j];
          }
          i += Z - 1;
        } else
          ans += a[i] ^ c[i] ^ u[i / Z];
      }
      cout << ans << endl;
    } else {
      int x;
      cin >> x;
      for (int i = l; i <= r; i++) {
        if (i % Z == 0 && i + Z - 1 <= r) {
          for (int j = 0; j < 20; j++) {
            if ((x >> j) & 1) b[i / Z][j] = Z - b[i / Z][j];
          }
          i += Z - 1;
          u[i / Z] ^= x;
          continue;
        }
        long long tmp = a[i] ^ c[i] ^ u[i / Z];
        for (int j = 0; j < 20; j++) {
          if ((x >> j) & 1 && (tmp >> j) & 1)
            b[i / Z][j]--;
          else if ((x >> j) & 1)
            b[i / Z][j]++;
        }
        c[i] ^= x;
      }
    }
  }
}
