#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100001;
const int NBITS = 22;
int inp_array[MAX_N];
struct segment_tree {
  segment_tree *left, *right;
  int fr, to, lazy;
  int cnt[NBITS];
  void update_cnt() {
    for (int i = 0; i < NBITS; ++i) cnt[i] = left->cnt[i] + right->cnt[i];
  }
  long long calc() {
    long long ans = 0;
    for (int i = 0; i < NBITS; ++i) ans += ((long long)cnt[i]) * (1LL << i);
    return ans;
  }
  void propagate() {
    if (lazy == 0) return;
    for (int i = 0; i < NBITS; ++i)
      if (lazy & (1 << i)) cnt[i] = (to - fr + 1) - cnt[i];
    if (left != NULL) {
      left->lazy ^= lazy;
      right->lazy ^= lazy;
    }
    lazy = 0;
  }
  long long query(int a, int b) {
    propagate();
    if (left != NULL) {
      left->propagate();
      right->propagate();
    }
    if (fr == a && to == b) return calc();
    if (left->to >= b) return left->query(a, b);
    if (right->fr <= a) return right->query(a, b);
    return left->query(a, left->to) + right->query(right->fr, b);
  }
  void range_xor(int a, int b, int v) {
    propagate();
    if (fr == a && to == b) {
      lazy = v;
      propagate();
      return;
    }
    if (left->to >= b) {
      left->range_xor(a, b, v);
      right->propagate();
    } else if (right->fr <= a) {
      left->propagate();
      right->range_xor(a, b, v);
    } else {
      left->range_xor(a, left->to, v);
      right->range_xor(right->fr, b, v);
    }
    update_cnt();
  }
  segment_tree(int a, int b) {
    fr = a, to = b;
    lazy = 0;
    if (fr == to) {
      for (int i = 0; i < NBITS; ++i)
        cnt[i] = ((inp_array[a] & (1 << i)) ? 1 : 0);
      left = right = NULL;
    } else {
      left = new segment_tree(fr, (fr + to) / 2);
      right = new segment_tree((fr + to) / 2 + 1, to);
      update_cnt();
    }
  }
  segment_tree() {}
};
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &inp_array[i]);
  segment_tree segtree(1, n);
  int nq, t, a, b, v;
  scanf("%d", &nq);
  for (int i = 0; i < nq; ++i) {
    scanf("%d", &t);
    if (t == 1) {
      scanf("%d%d", &a, &b);
      cout << segtree.query(a, b) << endl;
    } else {
      scanf("%d%d%d", &a, &b, &v);
      segtree.range_xor(a, b, v);
    }
  }
  return 0;
}
