#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 18;
int n, arr[N];
struct node {
  long long sum;
  int freq0[20];
  int freq1[20];
};
node tree[N << 1];
int lazy[N << 1];
struct segT {
  node merge(const node& l, const node& r) {
    node res;
    res.sum = l.sum + r.sum;
    for (int i = 0; i < 20; ++i) {
      res.freq0[i] = l.freq0[i] + r.freq0[i];
      res.freq1[i] = l.freq1[i] + r.freq1[i];
    }
    return res;
  }
  void build(int idx = 0, int st = 0, int en = n - 1) {
    if (st == en) {
      tree[idx].sum = arr[st];
      for (int j = 0; j < 20; ++j) {
        if (((arr[st] >> j) & 1) == 1) {
          tree[idx].freq1[j] = 1;
          tree[idx].freq0[j] = 0;
        } else {
          tree[idx].freq0[j] = 1;
          tree[idx].freq1[j] = 0;
        }
      }
      return;
    }
    int li = 2 * idx + 1, ri = li + 1, m = st + (en - st) / 2;
    build(li, st, m);
    build(ri, m + 1, en);
    tree[idx] = merge(tree[li], tree[ri]);
  }
  void push_down(int idx, int st, int en) {
    for (int i = 0, j = 1; i < 20; ++i, j *= 2) {
      if (((lazy[idx] >> i) & 1) == 1) {
        tree[idx].sum += 1ll * j * (tree[idx].freq0[i] - tree[idx].freq1[i]);
        swap(tree[idx].freq1[i], tree[idx].freq0[i]);
      }
    }
    if (st != en) {
      lazy[2 * idx + 1] ^= lazy[idx];
      lazy[2 * idx + 2] ^= lazy[idx];
    }
    lazy[idx] = 0;
  }
  void update(int l, int r, int val, int idx = 0, int st = 0, int en = n - 1) {
    push_down(idx, st, en);
    if (l > en || r < st) return;
    if (st >= l && en <= r) {
      lazy[idx] ^= val;
      push_down(idx, st, en);
      return;
    }
    int li = 2 * idx + 1, ri = li + 1, m = st + (en - st) / 2;
    update(l, r, val, li, st, m);
    update(l, r, val, ri, m + 1, en);
    tree[idx] = merge(tree[li], tree[ri]);
  }
  long long qu(int l, int r, int idx = 0, int st = 0, int en = n - 1) {
    push_down(idx, st, en);
    if (l > en || r < st) return 0;
    if (st >= l && en <= r) return tree[idx].sum;
    int li = 2 * idx + 1, ri = li + 1, m = st + (en - st) / 2;
    return qu(l, r, li, st, m) + qu(l, r, ri, m + 1, en);
  }
};
int main() {
  cin.tie(0), cin.sync_with_stdio(0);
o:
  int m, l, r, val, st;
  segT sgt;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  sgt.build();
  cin >> m;
  while (m--) {
    cin >> st;
    switch (st) {
      case 2: {
        cin >> l >> r >> val;
        --l, --r;
        sgt.update(l, r, val);
        break;
      }
      case 1: {
        cin >> l >> r;
        --l, --r;
        cout << sgt.qu(l, r) << "\n";
        break;
      }
    }
  }
  return 0;
}
