#include <bits/stdc++.h>
using namespace std;
bool x[100000][24];
int segtree[400000][24];
bool lazy[400000][24];
void build(int pos, int l, int r) {
  if (l == r) {
    for (int i = 0; i < 24; i++) segtree[pos][i] = x[l][i];
    return;
  }
  int mid = l + (r - l) / 2;
  build(pos * 2 + 1, l, mid);
  build(pos * 2 + 2, mid + 1, r);
  for (int i = 0; i < 24; i++)
    segtree[pos][i] = segtree[pos * 2 + 1][i] + segtree[pos * 2 + 2][i];
}
void update(int pos, int l, int r, int a, int b, int i) {
  if (lazy[pos][i]) {
    segtree[pos][i] = (r - l + 1) - segtree[pos][i];
    if (l != r) {
      lazy[pos * 2 + 1][i] ^= 1;
      lazy[pos * 2 + 2][i] ^= 1;
    }
    lazy[pos][i] = 0;
  }
  if (r < a || l > r || l > b) return;
  if (a <= l && b >= r) {
    segtree[pos][i] = (r - l + 1) - segtree[pos][i];
    if (l != r) {
      lazy[pos * 2 + 1][i] ^= 1;
      lazy[pos * 2 + 2][i] ^= 1;
    }
    return;
  }
  int mid = l + (r - l) / 2;
  update(pos * 2 + 1, l, mid, a, b, i);
  update(pos * 2 + 2, mid + 1, r, a, b, i);
  segtree[pos][i] = segtree[pos * 2 + 1][i] + segtree[pos * 2 + 2][i];
}
int query(int pos, int l, int r, int a, int b, int i) {
  if (lazy[pos][i]) {
    segtree[pos][i] = (r - l + 1) - segtree[pos][i];
    if (l != r) {
      lazy[pos * 2 + 1][i] ^= 1;
      lazy[pos * 2 + 2][i] ^= 1;
    }
    lazy[pos][i] = 0;
  }
  if (r < a || l > r || l > b) return 0;
  if (a <= l && b >= r) {
    return segtree[pos][i];
  }
  int mid = l + (r - l) / 2;
  return query(pos * 2 + 1, l, mid, a, b, i) +
         query(pos * 2 + 2, mid + 1, r, a, b, i);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int i, j, n, m, aa;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> aa;
    for (j = 0; j < 24; j++) x[i][j] = ((aa >> j) & 1);
  }
  build(0, 0, n - 1);
  cin >> m;
  while (m--) {
    long long t, l, r, ss, ans;
    cin >> t;
    if (t == 1) {
      cin >> l >> r;
      l--;
      r--;
      ans = 0;
      for (i = 0; i < 24; i++) {
        ans += 1LL * ((1LL << i) * query(0, 0, n - 1, l, r, i));
      }
      cout << ans << "\n";
    } else {
      cin >> l >> r >> ss;
      l--, r--;
      for (i = 0; i < 24; i++)
        if (((ss >> i) & 1)) update(0, 0, n - 1, l, r, i);
    }
  }
  return 0;
}
