#include <bits/stdc++.h>
using namespace std;
void data() {}
void win() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }
int block = 400;
const long double eps = 1e-7;
const int N = 3e5 + 500;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
const long long hh = 29;
const long long hh2 = 31;
int n, a[N];
int m;
struct segt {
  int t[N * 4];
  bool m[N * 4];
  void upd(int pos, int val, int v = 1, int tl = 1, int tr = n) {
    if (tl == tr) {
      t[v] = 1;
      return;
    }
    int tm = (tl + tr) / 2;
    if (pos <= tm)
      upd(pos, val, v * 2, tl, tm);
    else
      upd(pos, val, v * 2 + 1, tm + 1, tr);
    t[v] = t[v + v] + t[v + v + 1];
  }
  void push(int v, int tl, int tr) {
    if (m[v]) {
      t[v] = (tr - tl + 1) - t[v];
      m[v + v] ^= m[v];
      m[v + v + 1] ^= m[v];
      m[v] = 0;
    }
  }
  long long get(int l, int r, int v = 1, int tl = 1, int tr = n) {
    push(v, tl, tr);
    if (l <= tl && tr <= r) return t[v];
    if (l > tr || r < tl) return 0;
    int tm = (tl + tr) / 2;
    return get(l, r, v * 2, tl, tm) + get(l, r, v * 2 + 1, tm + 1, tr);
  }
  void modify(int l, int r, int v = 1, int tl = 1, int tr = n) {
    push(v, tl, tr);
    if (l <= tl && tr <= r) {
      m[v] = 1;
      push(v, tl, tr);
      return;
    }
    if (l > tr || r < tl) return;
    int tm = (tl + tr) / 2;
    modify(l, r, v * 2, tl, tm);
    modify(l, r, v * 2 + 1, tm + 1, tr);
    t[v] = t[v + v] + t[v + v + 1];
  }
} t[25];
int main() {
  data();
  win();
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    for (int j = 0; j <= 20; j++) {
      if ((a[i] >> j) & 1) t[j].upd(i, 1);
    }
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int type;
    cin >> type;
    if (type == 1) {
      int l, r;
      cin >> l >> r;
      long long ans = 0;
      for (int j = 0; j <= 20; j++) {
        ans += t[j].get(l, r) * (1LL << j);
      }
      cout << ans << '\n';
    } else {
      int l, r, x;
      cin >> l >> r >> x;
      for (int j = 0; j <= 20; j++) {
        if ((x >> j) & 1) {
          t[j].modify(l, r);
        }
      }
    }
  }
}
