#include <bits/stdc++.h>
using namespace std;
int maxn = 21;
vector<int> A, lazy;
vector<vector<int>> st;
inline int left(int node) { return node << 1; }
inline int right(int node) { return (node << 1) + 1; }
void build(int node, int L, int R) {
  if (L == R) {
    st[node].clear();
    st[node].resize(maxn);
    for (int i = 0; i < maxn; i++) {
      if (A[L] & (1 << i)) st[node][i] = 1;
    }
  } else {
    build(left(node), L, (L + R) / 2);
    build(right(node), (L + R) / 2 + 1, R);
    st[node].clear();
    st[node].resize(maxn);
    for (int i = 0; i < maxn; i++)
      st[node][i] = st[left(node)][i] + st[right(node)][i];
  }
}
void shift(int node, int L, int R) {
  if (L != R) {
    lazy[left(node)] ^= lazy[node];
    for (int i = 0; i < maxn; i++) {
      if ((lazy[node] & (1 << i))) {
        st[left(node)][i] = ((L + R) / 2 - L + 1) - st[left(node)][i];
      }
    }
    lazy[right(node)] ^= lazy[node];
    for (int i = 0; i < maxn; i++) {
      if ((lazy[node] & (1 << i))) {
        st[right(node)][i] = (R - ((L + R) / 2)) - st[right(node)][i];
      }
    }
    lazy[node] = 0;
  }
}
void upd(int node, int L, int R, int a, int b, int v) {
  if (a > R || b < L)
    return;
  else if (a <= L && R <= b) {
    lazy[node] ^= v;
    for (int i = 0; i < maxn; i++) {
      if ((v & (1 << i))) {
        st[node][i] = (R - L + 1) - st[node][i];
      }
    }
  } else {
    shift(node, L, R);
    upd(left(node), L, (L + R) / 2, a, b, v);
    upd(right(node), (L + R) / 2 + 1, R, a, b, v);
    for (int i = 0; i < maxn; i++)
      st[node][i] = st[left(node)][i] + st[right(node)][i];
  }
}
vector<int> qry(int node, int L, int R, int a, int b) {
  if (a > R || b < L)
    return vector<int>(maxn, 0);
  else if (a <= L && R <= b)
    return st[node];
  else {
    shift(node, L, R);
    vector<int> p1 = qry(left(node), L, (L + R) / 2, a, b);
    vector<int> p2 = qry(right(node), (L + R) / 2 + 1, R, a, b);
    vector<int> p(maxn);
    for (int i = 0; i < maxn; i++) p[i] = p1[i] + p2[i];
    return p;
  }
}
int main(void) {
  int n;
  scanf("%d", &n);
  A.clear();
  A.resize(n);
  st.clear();
  st.resize(4 * n, vector<int>(maxn));
  lazy.clear();
  lazy.resize(4 * n);
  for (int i = 0; i < n; i++) scanf("%d", &A[i]);
  build(1, 0, n - 1);
  int m, type, x, y, k;
  long long int res, pw = 1;
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &type);
    if (type == 1) {
      scanf("%d%d", &x, &y);
      res = 0;
      pw = 1;
      vector<int> mask = qry(1, 0, n - 1, x - 1, y - 1);
      for (int i = 0; i < maxn; i++) {
        res += pw * mask[i];
        pw *= 2;
      }
      printf("%lld\n", res);
    } else {
      scanf("%d%d%d", &x, &y, &k);
      upd(1, 0, n - 1, x - 1, y - 1, k);
    }
  }
}
