#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
const int N = 1 << 17;
int s[20][2 * N];
int p[20][2 * N];
int L[2 * N], R[2 * N];
void PUSH(int* s, int* p, int v) {
  if (p[v]) {
    p[2 * v] ^= 1;
    p[2 * v + 1] ^= 1;
    s[2 * v] = R[2 * v] - L[2 * v] - s[2 * v];
    s[2 * v + 1] = R[2 * v + 1] - L[2 * v + 1] - s[2 * v + 1];
    p[v] = 0;
  }
}
void UP(int* s, int v) { s[v] = s[2 * v] + s[2 * v + 1]; }
void XOR(int* s, int* p, int v, int L, int R) {
  if (L >= R) return;
  if (L == ::L[v] && R == ::R[v]) {
    s[v] = R - L - s[v];
    p[v] ^= 1;
    return;
  }
  PUSH(s, p, v);
  int M = (::L[v] + ::R[v]) / 2;
  XOR(s, p, 2 * v, L, min(M, R));
  XOR(s, p, 2 * v + 1, max(M, L), R);
  UP(s, v);
}
int SUM(int* s, int* p, int v, int L, int R) {
  if (L >= R) return 0;
  if (L == ::L[v] && R == ::R[v]) return s[v];
  PUSH(s, p, v);
  int M = (::L[v] + ::R[v]) / 2;
  int res = SUM(s, p, 2 * v, L, min(M, R)) + SUM(s, p, 2 * v + 1, max(M, L), R);
  UP(s, v);
  return res;
}
int n, m;
int main() {
  memset(L, -1, sizeof(L));
  memset(R, -1, sizeof(R));
  for (int i = 0; i < N; ++i) {
    L[N + i] = i;
    R[N + i] = i + 1;
  }
  for (int i = N - 1; i > 0; --i) L[i] = L[2 * i], R[i] = R[2 * i + 1];
  memset(p, 0, sizeof(p));
  memset(s, 0, sizeof(s));
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    for (int bit = 0; bit < 20; ++bit)
      if (x & (1 << bit)) XOR(s[bit], p[bit], 1, i, i + 1);
  }
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int t;
    scanf("%d", &t);
    int L, R, X;
    if (t == 1) {
      scanf("%d%d", &L, &R);
      L--;
      long long res = 0;
      for (int bit = 0; bit < 20; ++bit)
        res += (long long)SUM(s[bit], p[bit], 1, L, R) << bit;
      printf("%I64d\n", res);
    } else {
      scanf("%d%d%d", &L, &R, &X);
      L--;
      for (int bit = 0; bit < 20; ++bit)
        if (X & (1 << bit)) XOR(s[bit], p[bit], 1, L, R);
    }
  }
  return 0;
}
