#include <bits/stdc++.h>
using namespace std;
long long tree[262145], lazy[262145], v[100001], da[262145][21];
void build(int node, int a, int b) {
  if (a > b) return;
  if (a == b) {
    tree[node] = v[a];
    for (int i = 0; i <= 20; i++) da[node][i] = ((v[a] >> i) & 1);
    return;
  }
  build(node << 1, a, (a + b) >> 1);
  build(node << 1 | 1, 1 + ((a + b) >> 1), b);
  tree[node] = tree[node << 1] + tree[node << 1 | 1];
  for (int i = 0; i <= 20; i++)
    da[node][i] = da[node << 1][i] + da[node << 1 | 1][i];
}
void update(int node, int a, int b, int i, int j, long long value) {
  if (lazy[node] != 0) {
    for (int ii = 0; ii <= 20; ii++)
      if ((lazy[node] >> ii) & 1)
        tree[node] += ((long long)(b - a + 1) - 2 * da[node][ii]) << ii,
            da[node][ii] = (b - a + 1) - da[node][ii];
    if (a != b) {
      lazy[node << 1] ^= lazy[node];
      lazy[node << 1 | 1] ^= lazy[node];
    }
    lazy[node] = 0;
  }
  if (a > b || a > j || b < i) return;
  if (a >= i && b <= j) {
    for (int ii = 0; ii <= 20; ii++)
      if ((value >> ii) & 1)
        tree[node] += ((long long)(b - a + 1) - 2 * da[node][ii]) << ii,
            da[node][ii] = (b - a + 1) - da[node][ii];
    if (a != b) {
      lazy[node << 1] ^= value;
      lazy[node << 1 | 1] ^= value;
    }
    return;
  }
  update(node << 1, a, (a + b) >> 1, i, j, value);
  update(node << 1 | 1, 1 + ((a + b) >> 1), b, i, j, value);
  tree[node] = tree[node << 1] + tree[node << 1 | 1];
  for (int i = 0; i <= 20; i++)
    da[node][i] = da[node << 1][i] + da[node << 1 | 1][i];
}
long long query(int node, int a, int b, int i, int j) {
  if (a > b || a > j || b < i) return 0;
  if (lazy[node] != 0) {
    for (int ii = 0; ii <= 20; ii++)
      if ((lazy[node] >> ii) & 1)
        tree[node] += ((long long)(b - a + 1) - 2 * da[node][ii]) << ii,
            da[node][ii] = (b - a + 1) - da[node][ii];
    if (a != b) {
      lazy[node << 1] ^= lazy[node];
      lazy[node << 1 | 1] ^= lazy[node];
    }
    lazy[node] = 0;
  }
  if (a >= i && b <= j) return tree[node];
  return query(node << 1, a, (a + b) >> 1, i, j) +
         query(node << 1 | 1, ((a + b) >> 1) + 1, b, i, j);
}
int main() {
  int t, n, a, x, y, z, q;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%I64d", &v[i]);
  build(1, 0, n - 1);
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d %d", &a, &x, &y);
    if (a == 1) {
      printf("%I64d\n", query(1, 0, n - 1, x - 1, y - 1));
    } else {
      scanf("%d", &a);
      update(1, 0, n - 1, x - 1, y - 1, (long long)a);
    }
  }
}
