#include <bits/stdc++.h>
using namespace std;
int XOR[(1 << 18) + 100];
vector<int> dp[(1 << 18) + 100];
vector<int> get(int root, int st, int ed, int lo, int hi) {
  if (st > hi || lo > ed) return vector<int>(20, 0);
  if (st >= lo && ed <= hi) return dp[root];
  int mid = (st + ed) / 2, L = root << 1, R = (root << 1) + 1;
  vector<int> ll = get(L, st, mid, lo, hi);
  vector<int> rr = get(R, mid + 1, ed, lo, hi);
  vector<int> res(20, 0);
  int dis = min(ed, hi) - max(st, lo) + 1;
  for (int i = 0; i < 20; i++) {
    res[i] = rr[i] + ll[i];
    if (XOR[root] & (1 << i)) res[i] = dis - res[i];
  }
  return res;
}
void add(int root, int st, int ed, int lo, int hi, int co) {
  if (lo > ed || st > hi) return;
  if (lo <= st && hi >= ed) {
    XOR[root] ^= co;
    for (int i = 0; i < 20; i++) {
      if (co & (1 << i)) {
        dp[root][i] = (ed - st + 1) - dp[root][i];
      }
    }
    return;
  }
  int mid = (st + ed) / 2, L = root << 1, R = (root << 1) + 1;
  add(L, st, mid, lo, hi, co);
  add(R, mid + 1, ed, lo, hi, co);
  for (int i = 0; i < 20; i++) {
    dp[root][i] = dp[L][i] + dp[R][i];
    if (XOR[root] & (1 << i)) {
      dp[root][i] = (ed - st + 1) - dp[root][i];
    }
  }
}
int main() {
  for (int i = 0; i < (1 << 18) + 100; i++) dp[i] = vector<int>(20, 0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    add(1, 1, n, i, i, a);
  }
  int m;
  cin >> m;
  while (m--) {
    int t, a, b;
    cin >> t >> a >> b;
    if (t == 1) {
      vector<int> res = get(1, 1, n, a, b);
      long long ans = 0;
      for (int i = 0; i < 20; i++) ans = ans + (1LL << i) * res[i];
      cout << ans << endl;
    } else {
      int c;
      cin >> c;
      add(1, 1, n, a, b, c);
    }
  }
  return 0;
}
