#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
struct lazy_st {
  vector<int> tree, lazy;
  int sz;
  lazy_st() {}
  void build(int n) {
    tree.assign((sz = n) << 2, 0);
    lazy.assign(n << 2, 0);
  }
  void push(int pos, int l, int r) {
    if (lazy[pos] & 1) {
      tree[pos] = (1 + r - l) - tree[pos];
    }
    if (l != r) {
      lazy[((pos << 1) | 1)] += lazy[pos];
      lazy[(1 + ((pos << 1) | 1))] += lazy[pos];
    }
    lazy[pos] = 0LL;
  }
  int query(const int& ql, const int& qr, int low, int high, int pos) {
    push(pos, low, high);
    if (qr < low || ql > high) return 0LL;
    if (low >= ql && high <= qr) return tree[pos];
    return query(ql, qr, low, ((low + high) >> 1), ((pos << 1) | 1)) +
           query(ql, qr, 1 + ((low + high) >> 1), high, (1 + ((pos << 1) | 1)));
  }
  int query(int l, int r) { return query(l, r, 0, sz - 1, 0); }
  int update(const int& ql, const int& qr, int low, int high, int pos) {
    push(pos, low, high);
    if (qr < low || ql > high) return tree[pos];
    if (low >= ql && high <= qr) {
      ++lazy[pos];
      push(pos, low, high);
      return tree[pos];
    }
    return tree[pos] =
               update(ql, qr, low, ((low + high) >> 1), ((pos << 1) | 1)) +
               update(ql, qr, 1 + ((low + high) >> 1), high,
                      (1 + ((pos << 1) | 1)));
  }
  void update(int l, int r) { update(l, r, 0, sz - 1, 0); }
};
const int MAXB = 22;
lazy_st st[MAXB];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  for (int i = (int)0; i < (int)MAXB; ++i) st[i].build(n);
  for (int i = (int)0; i < (int)n; ++i) {
    int x;
    cin >> x;
    for (int j = (int)0; j < (int)MAXB; ++j) {
      if (x & (1 << j)) {
        st[j].update(i, i);
      }
    }
  }
  int q;
  cin >> q;
  while (q--) {
    int t, l, r;
    cin >> t >> l >> r;
    --l;
    --r;
    if (t == 1) {
      ll ans = 0LL;
      for (int i = (int)0; i < (int)MAXB; ++i)
        ans += (1LL * (1 << i) * st[i].query(l, r));
      cout << ans << '\n';
    } else {
      assert(t == 2);
      int x;
      cin >> x;
      for (int i = (int)0; i < (int)MAXB; ++i) {
        if (x & (1 << i)) {
          st[i].update(l, r);
        }
      }
    }
  }
  return 0;
}
