#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
const int inf = 1 << 29;
int sum[maxn << 2][25], col[maxn << 2];
long long res;
void pushup(int rt) {
  for (int i = 0; i <= 23; i++)
    sum[rt][i] = sum[rt << 1][i] + sum[rt << 1 | 1][i];
}
void build(int l, int r, int rt) {
  col[rt] = 0;
  if (l == r) {
    int a;
    scanf("%d", &a);
    for (int i = 0; i <= 23; i++) {
      sum[rt][i] = (a & (1 << i)) ? 1 : 0;
    }
    return;
  }
  int m = (l + r) >> 1;
  build(l, m, rt << 1);
  build(m + 1, r, rt << 1 | 1);
  pushup(rt);
}
void pushdown(int l, int r, int rt) {
  if (col[rt]) {
    col[rt << 1] ^= col[rt];
    col[rt << 1 | 1] ^= col[rt];
    int m = (l + r) >> 1;
    for (int i = 0; i <= 23; i++) {
      if (col[rt] & (1 << i)) {
        sum[rt << 1][i] = (m - l + 1) - sum[rt << 1][i];
        sum[rt << 1 | 1][i] = (r - m) - sum[rt << 1 | 1][i];
      }
    }
    col[rt] = 0;
  }
}
void query(int ll, int rr, int l, int r, int rt) {
  if (ll <= l && r <= rr) {
    for (int i = 0; i <= 23; i++) res += (long long)sum[rt][i] * (1 << i);
    return;
  }
  pushdown(l, r, rt);
  int m = (l + r) >> 1;
  if (ll <= m) query(ll, rr, l, m, rt << 1);
  if (rr > m) query(ll, rr, m + 1, r, rt << 1 | 1);
}
void update(int ll, int rr, int c, int l, int r, int rt) {
  if (ll <= l && r <= rr) {
    col[rt] = col[rt] ^ c;
    for (int i = 0; i <= 23; i++) {
      if (c & (1 << i)) {
        sum[rt][i] = (r - l + 1) - sum[rt][i];
      }
    }
    return;
  }
  pushdown(l, r, rt);
  int m = (l + r) >> 1;
  if (ll <= m) update(ll, rr, c, l, m, rt << 1);
  if (rr > m) update(ll, rr, c, m + 1, r, rt << 1 | 1);
  pushup(rt);
}
int main() {
  int n, q, a, b, c, d;
  scanf("%d", &n);
  build(1, n, 1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d", &a);
    if (a == 1) {
      scanf("%d%d", &b, &c);
      res = 0;
      query(b, c, 1, n, 1);
      printf("%I64d\n", res);
    } else {
      scanf("%d%d%d", &b, &c, &d);
      update(b, c, d, 1, n, 1);
    }
  }
}
