#include <bits/stdc++.h>
using namespace std;
struct node {
  int a[22];
};
int sum[100005 << 2][22], col[100005 << 2][22];
long long h[22];
void PushDown(int len, int now) {
  int i;
  for (i = 0; i < 20; i++)
    if (col[now][i]) {
      sum[now << 1][i] = (len - (len >> 1)) - sum[now << 1][i];
      sum[(now << 1) | 1][i] = (len >> 1) - sum[(now << 1) | 1][i];
      col[now << 1][i] = 1 - col[now << 1][i];
      col[(now << 1) | 1][i] = 1 - col[(now << 1) | 1][i];
    }
  for (i = 0; i < 20; i++) col[now][i] = 0;
  return;
}
void update(int L, int R, int x, int l, int r, int now) {
  int i;
  if (L <= l && R >= r) {
    for (i = 0; i < 20; i++)
      if (x & (1 << i)) {
        sum[now][i] = (r - l + 1) - sum[now][i];
        col[now][i] = 1 - col[now][i];
      }
    return;
  }
  PushDown(r - l + 1, now);
  int mid = (l + r) >> 1;
  if (L <= mid) update(L, R, x, l, mid, now << 1);
  if (R > mid) update(L, R, x, mid + 1, r, (now << 1) | 1);
  for (i = 0; i < 20; i++)
    sum[now][i] = sum[now << 1][i] + sum[(now << 1) | 1][i];
  return;
}
node query(int L, int R, int l, int r, int now) {
  int i;
  node h;
  memset(h.a, 0, sizeof(h.a));
  if (L <= l && R >= r) {
    for (i = 0; i < 20; i++) h.a[i] = sum[now][i];
    return h;
  }
  PushDown(r - l + 1, now);
  int mid = (l + r) >> 1;
  if (L <= mid) {
    node p = query(L, R, l, mid, now << 1);
    for (i = 0; i < 20; i++) h.a[i] += p.a[i];
  }
  if (R > mid) {
    node p = query(L, R, mid + 1, r, (now << 1) | 1);
    for (i = 0; i < 20; i++) h.a[i] += p.a[i];
  }
  return h;
}
int main() {
  int i, n, m;
  while (~scanf("%d", &n)) {
    memset(sum, 0, sizeof(sum));
    memset(col, 0, sizeof(col));
    for (i = 1; i <= n; i++) {
      int x;
      scanf("%d", &x);
      update(i, i, x, 1, n, 1);
    }
    scanf("%d", &m);
    while (m--) {
      int tp, l, r;
      scanf("%d%d%d", &tp, &l, &r);
      if (tp == 1) {
        long long ans, x;
        node h = query(l, r, 1, n, 1);
        ans = 0, x = 1;
        for (i = 0; i < 20; i++) {
          ans += x * h.a[i];
          x *= 2;
        }
        printf("%I64d\n", ans);
      } else {
        int x;
        scanf("%d", &x);
        update(l, r, x, 1, n, 1);
      }
    }
  }
  return 0;
}
