#include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
long long MAX = 1e17;
int lazy[30][4 * 100005], a[30][100005], s[30][4 * 100005];
void build(int id, int lo, int hi, int index) {
  if (lo == hi) {
    s[index][id] = a[index][lo];
    return;
  }
  int mid = (lo + hi) / 2;
  build(2 * id, lo, mid, index);
  build(2 * id + 1, mid + 1, hi, index);
  s[index][id] = s[index][2 * id] + s[index][2 * id + 1];
}
void upd(int id, int lo, int hi, int l, int r, int index) {
  if (l > hi or r < lo) return;
  if (lazy[index][id] == 1) {
    s[index][id] = (hi - lo + 1) - s[index][id];
    lazy[index][id] = 0;
    if (lo != hi) {
      lazy[index][2 * id] = 1 - lazy[index][2 * id];
      lazy[index][2 * id + 1] = 1 - lazy[index][2 * id + 1];
    }
  }
  if (l <= lo and r >= hi) {
    lazy[index][id] = 1;
    return;
  }
  if (lo == hi) return;
  int mid = (lo + hi) / 2;
  upd(2 * id, lo, mid, l, r, index);
  upd(2 * id + 1, mid + 1, hi, l, r, index);
  if (lazy[index][2 * id] == 1)
    s[index][id] = ((mid - lo + 1) - s[index][2 * id]);
  else
    s[index][id] = s[index][2 * id];
  if (lazy[index][2 * id + 1] == 1)
    s[index][id] += ((hi - mid) - s[index][2 * id + 1]);
  else
    s[index][id] += s[index][2 * id + 1];
}
int query(int id, int lo, int hi, int l, int r, int index) {
  if (l > hi or r < lo) return 0;
  if (lazy[index][id] == 1) {
    s[index][id] = (hi - lo + 1) - s[index][id];
    lazy[index][id] = 0;
    if (lo != hi) {
      lazy[index][2 * id] = 1 - lazy[index][2 * id];
      lazy[index][2 * id + 1] = 1 - lazy[index][2 * id + 1];
    }
  }
  if (l <= lo and r >= hi) {
    return s[index][id];
  }
  int mid = (lo + hi) / 2;
  return query(2 * id, lo, mid, l, r, index) +
         query(2 * id + 1, mid + 1, hi, l, r, index);
}
int main() {
  ios_base::sync_with_stdio(0);
  ;
  int n, m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    for (int j = 29; j >= 0; j--) {
      if (x & (1 << j)) {
        a[j][i + 1] = 1;
      }
    }
  }
  for (int j = 29; j >= 0; j--) {
    build(1, 1, n, j);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int type, l, r, x;
    cin >> type >> l >> r;
    if (type == 2) {
      cin >> x;
      for (int j = 29; j >= 0; j--) {
        if (x & (1 << j)) {
          upd(1, 1, n, l, r, j);
        }
      }
    } else {
      long long ans = 0ll;
      for (int j = 29; j >= 0; j--) {
        ans += (1ll << (long long)j) * ((long long)query(1, 1, n, l, r, j));
      }
      cout << ans << endl;
    }
  }
}
