#include <bits/stdc++.h>
int diru[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dirv[] = {-1, 0, 1, -1, 1, -1, 0, 1};
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
template <class T>
T sq(T n) {
  return n * n;
}
template <class T>
T gcd(T a, T b) {
  return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
  return (a / gcd<T>(a, b) * b);
}
template <class T>
bool inside(T a, T b, T c) {
  return a <= b && b <= c;
}
template <class T>
void setmax(T& a, T b) {
  if (a < b) a = b;
}
template <class T>
void setmin(T& a, T b) {
  if (b < a) a = b;
}
template <class T>
T power(T N, T P) {
  return (P == 0) ? 1 : N * power(N, P - 1);
}
struct X {
  int cnt[22];
  int x;
};
X tree[400010];
int in[400010];
int x, y;
long long int ans[30];
int val;
X eval(X u, int len) {
  int i;
  for (i = 0; i < 22; i++) {
    if ((u.x) & (1 << i)) u.cnt[i] = len - u.cnt[i];
  }
  return u;
}
X init(int b, int e, int node) {
  int i;
  if (b == e) {
    memset(tree[node].cnt, 0, sizeof(tree[node].cnt));
    tree[node].x = 0;
    for (i = 0; i < 22; i++)
      if (in[b] & (1 << i)) tree[node].cnt[i]++;
    return tree[node];
  }
  int m = (b + e) >> 1, u = node << 1;
  int v = u + 1;
  tree[node].x = 0;
  X p = init(b, m, u);
  X q = init(m + 1, e, v);
  for (i = 0; i < 22; i++) tree[node].cnt[i] = p.cnt[i] + q.cnt[i];
  return tree[node];
}
X update(int b, int e, int node) {
  if (b > y || e < x) return eval(tree[node], e - b + 1);
  int i;
  if (b >= x && e <= y) {
    tree[node].x ^= val;
    return eval(tree[node], e - b + 1);
  }
  int m = (b + e) >> 1, u = node << 1;
  int v = u + 1;
  tree[u].x ^= tree[node].x;
  tree[v].x ^= tree[node].x;
  tree[node].x = 0;
  X p = update(b, m, u);
  X q = update(m + 1, e, v);
  for (i = 0; i < 22; i++) tree[node].cnt[i] = p.cnt[i] + q.cnt[i];
  return tree[node];
}
X query(int b, int e, int node) {
  if (b > y || e < x) return eval(tree[node], e - b + 1);
  int i;
  if (b >= x && e <= y) {
    X ret = eval(tree[node], e - b + 1);
    for (i = 0; i < 22; i++) ans[i] += ret.cnt[i];
    return ret;
  }
  int m = (b + e) >> 1, u = node << 1;
  int v = u + 1;
  tree[u].x ^= tree[node].x;
  tree[v].x ^= tree[node].x;
  tree[node].x = 0;
  X p = query(b, m, u);
  X q = query(m + 1, e, v);
  for (i = 0; i < 22; i++) tree[node].cnt[i] = p.cnt[i] + q.cnt[i];
  return tree[node];
}
long long int solve() {
  long long int ret = 0;
  int i;
  for (i = 0; i < 22; i++) {
    ret += (long long int)ans[i] * (1LL << i);
  }
  return ret;
}
int main() {
  int n, T, t = 1, m, i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &in[i]);
  init(0, n - 1, 1);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &k);
    if (k == 1) {
      scanf("%d", &x);
      scanf("%d", &y);
      x--;
      y--;
      memset(ans, 0, sizeof(ans));
      query(0, n - 1, 1);
      printf("%lld\n", solve());
    } else {
      scanf("%d", &x);
      scanf("%d", &y);
      scanf("%d", &val);
      x--;
      y--;
      update(0, n - 1, 1);
    }
  }
  return 0;
}
