#include <bits/stdc++.h>
using namespace std;
int n;
int m;
const int maxn = 100005;
int b[maxn];
struct tree {
  int a[maxn * 4];
  int lazy[maxn * 4];
  void add(int x, int l, int r, int wh) {
    if (l == r) {
      if (l == wh) {
        a[x] = 1;
      }
      return;
    }
    int mid = (l + r) >> 1;
    if (wh <= mid)
      add(x * 2, l, mid, wh);
    else
      add(x * 2 + 1, mid + 1, r, wh);
    a[x] = a[x * 2] + a[x * 2 + 1];
  }
  void updown(int x, int l, int r) {
    if (!lazy[x]) return;
    if (l == r) {
      lazy[x] = 0;
      return;
    }
    int mid = (l + r) / 2;
    lazy[x * 2] ^= 1;
    a[x * 2] = (mid - l + 1) - a[x * 2];
    a[x * 2 + 1] = (r - mid) - a[x * 2 + 1];
    lazy[x * 2 + 1] ^= 1;
    lazy[x] = 0;
  }
  int query(int x, int l, int r, int tx, int ty) {
    if (l >= tx && r <= ty) {
      return a[x];
    }
    updown(x, l, r);
    int mid = (l + r) >> 1;
    int ret = 0;
    if (mid >= tx) ret += query(x * 2, l, mid, tx, ty);
    if (mid < ty) ret += query(x * 2 + 1, mid + 1, r, tx, ty);
    return ret;
  }
  void modify(int x, int l, int r, int tx, int ty) {
    if (l >= tx && r <= ty) {
      if (lazy[x] == 1)
        lazy[x] = 0;
      else
        lazy[x] = 1;
      a[x] = (r - l + 1) - a[x];
      return;
    }
    updown(x, l, r);
    int mid = (l + r) >> 1;
    if (mid >= tx) modify(x * 2, l, mid, tx, ty);
    if (mid < ty) modify(x * 2 + 1, mid + 1, r, tx, ty);
    a[x] = a[x * 2] + a[x * 2 + 1];
  }
} T[25];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 20; j++) {
      if (b[i] & (1 << j)) {
        T[j].add(1, 1, n, i);
      }
    }
  }
  scanf("%d", &m);
  while (m--) {
    int type;
    scanf("%d", &type);
    if (type == 1) {
      int x, y;
      scanf("%d%d", &x, &y);
      long long ans = 0;
      for (int j = 0; j <= 20; j++) {
        ans += (1 << j) * (long long)T[j].query(1, 1, n, x, y);
      }
      printf("%I64d\n", ans);
    } else {
      int x, y, z;
      scanf("%d%d%d", &x, &y, &z);
      for (int j = 0; j <= 20; j++) {
        if ((1 << j) & z) {
          T[j].modify(1, 1, n, x, y);
        }
      }
    }
  }
  return 0;
}
