#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int RT = 320;
int n;
int a[N];
int m;
int partSum[RT][20];
bool flag[RT];
int upd[RT];
long long int sum(int l, int r) {
  long long int ans = 0;
  if (flag[l / RT]) {
    for (int i = 0; i < 20; i++) {
      partSum[l / RT][i] = 0;
    }
    for (int i = (l / RT) * RT; i < (l / RT + 1) * RT && i < n; i++) {
      a[i] ^= upd[l / RT];
      int t = a[i];
      for (int j = 0; j < 20; j++) {
        partSum[l / RT][j] += (t % 2);
        t /= 2;
      }
    }
    upd[l / RT] = 0;
    flag[l / RT] = 0;
  }
  if (flag[r / RT]) {
    for (int i = 0; i < 20; i++) {
      partSum[r / RT][i] = 0;
    }
    for (int i = (r / RT) * RT; i < (r / RT + 1) * RT && i < n; i++) {
      a[i] ^= upd[r / RT];
      int t = a[i];
      for (int j = 0; j < 20; j++) {
        partSum[r / RT][j] += (t % 2);
        t /= 2;
      }
    }
    upd[r / RT] = 0;
    flag[r / RT] = 0;
  }
  if (l / RT == r / RT) {
    for (int i = l; i <= r; i++) {
      ans += a[i];
    }
  } else {
    int lCeil = (l / RT + 1) * RT;
    int rFloor = (r / RT) * RT;
    for (int i = l; i < lCeil; i++) {
      ans += a[i];
    }
    for (int i = lCeil; i < rFloor; i += RT) {
      long long int tem = 0;
      for (int j = 0; j < 20; j++) {
        if (upd[i / RT] & (1 << j)) {
          tem += ((long long int)(RT - partSum[i / RT][j])) * (1 << j);
        } else {
          tem += ((long long int)(partSum[i / RT][j])) * (1 << j);
        }
      }
      ans += tem;
    }
    for (int i = rFloor; i <= r; i++) {
      ans += a[i];
    }
  }
  return ans;
}
void update(int l, int r, int x) {
  if (l / RT == r / RT) {
    for (int i = 0; i < 20; i++) {
      partSum[l / RT][i] = 0;
    }
    for (int i = l; i <= r; i++) {
      a[i] ^= x;
    }
    for (int i = (r / RT) * RT; i < (r / RT + 1) * RT && i < n; i++) {
      int t = a[i];
      for (int j = 0; j < 20; j++) {
        partSum[l / RT][j] += (t % 2);
        t /= 2;
      }
    }
  } else {
    int lCeil = (l / RT + 1) * RT;
    int rFloor = (r / RT) * RT;
    for (int i = l; i < lCeil; i++) {
      a[i] ^= x;
    }
    for (int i = 0; i < 20; i++) {
      partSum[l / RT][i] = 0;
    }
    for (int i = (l / RT) * RT; i < (l / RT + 1) * RT && i < n; i++) {
      int t = a[i];
      for (int j = 0; j < 20; j++) {
        partSum[l / RT][j] += (t % 2);
        t /= 2;
      }
    }
    for (int i = lCeil; i < rFloor; i += RT) {
      flag[i / RT] = true;
      upd[i / RT] ^= x;
    }
    for (int i = rFloor; i <= r; i++) {
      a[i] ^= x;
    }
    for (int i = 0; i < 20; i++) {
      partSum[r / RT][i] = 0;
    }
    for (int i = rFloor; i < (r / RT + 1) * RT && i < n; i++) {
      int t = a[i];
      for (int j = 0; j < 20; j++) {
        partSum[r / RT][j] += (t % 2);
        t /= 2;
      }
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < RT; i++) {
    for (int j = 0; j < 20; j++) {
      partSum[i][j] = 0;
    }
  }
  memset(flag, 0, RT * sizeof(bool));
  memset(upd, 0, RT * sizeof(int));
  for (int i = 0; i < RT; i++) {
    for (int j = 0; j < RT; j++) {
      int k = i * RT + j;
      if (k == n) break;
      int tem = a[k];
      for (int ii = 0; ii < 20; ii++) {
        partSum[i][ii] += (tem % 2);
        tem /= 2;
      }
    }
    if ((i + 1) * RT > n) break;
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int t;
    cin >> t;
    if (t == 1) {
      int l, r;
      cin >> l >> r;
      l--;
      r--;
      cout << sum(l, r) << endl;
    } else {
      int l, r, x;
      cin >> l >> r >> x;
      l--;
      r--;
      update(l, r, x);
    }
  }
  return 0;
}
