#include <bits/stdc++.h>
using std::getchar;
using std::max;
using std::min;
using std::putchar;
struct segment_tree {
  int bit[20];
  int Re;
};
segment_tree t[131072 * 4];
int n, m, a[131072], sz;
inline void read(int &res);
void start();
void build(int v, int tl, int tr);
void push(int v, int k);
void update(int l, int r, int X, int v, int tl, int tr);
long long get_sum(int l, int r, int v, int tl, int tr);
void write(long long &sum);
void solve();
inline void write(long long &sum);
void solve();
char chr;
inline void read(int &res) {
  res = 0;
  while (chr = getchar(), chr <= '9' && chr >= '0') res = res * 10 + chr - '0';
}
char c[12];
int end;
inline void write(long long &sum) {
  if (!sum) putchar('0');
  for (; sum; sum /= 10) c[end++] = sum % 10 + '0';
  for (; end; --end) putchar(c[end - 1]);
  putchar('\n');
}
void build(int v = 1, int tl = 0, int tr = sz) {
  if (tl == tr) {
    if (tl > n - 1)
      t[v].Re = -1;
    else
      for (int i(0); i < 20; ++i) t[v].bit[i] = (a[tl] >> i) & 1;
    return;
  }
  int tm((tl + tr) >> 1);
  build(v << 1, tl, tm);
  build((v << 1) | 1, tm + 1, tr);
  if (t[v << 1].Re == -1 && t[(v << 1) | 1].Re == -1)
    t[v].Re = -1;
  else
    for (int i(0); i < 20; ++i)
      t[v].bit[i] = t[(v << 1) | 1].bit[i] + t[v << 1].bit[i];
  return;
}
void push(int v, int k) {
  if (t[v].Re > 0) {
    if (t[v << 1].Re != -1) {
      t[v << 1].Re ^= t[v].Re;
      for (int i(0); i < 20; ++i)
        if ((t[v].Re >> i) & 1) t[v << 1].bit[i] = k - t[v << 1].bit[i];
    }
    if (t[(v << 1) | 1].Re != -1) {
      t[(v << 1) | 1].Re ^= t[v].Re;
      for (int i(0); i < 20; ++i)
        if ((t[v].Re >> i) & 1)
          t[(v << 1) | 1].bit[i] = k - t[(v << 1) | 1].bit[i];
    }
    t[v].Re = 0;
  }
  return;
}
void update(int l, int r, int X, int v = 1, int tl = 0, int tr = sz) {
  if (r < l || t[v].Re == -1) return;
  push(v, (tr - tl + 1) >> 1);
  if (tl == l && tr == r) {
    t[v].Re ^= X;
    for (int i(0); i < 20; ++i)
      if ((X >> i) & 1) t[v].bit[i] = tr - tl + 1 - t[v].bit[i];
    push(v, (tr - tl + 1) >> 1);
    return;
  }
  int tm((tr + tl) >> 1);
  update(l, (min(tm, r)), X, v << 1, tl, tm);
  update(max(tm + 1, l), r, X, (v << 1) | 1, tm + 1, tr);
  for (int i(0); i < 20; ++i)
    t[v].bit[i] = t[v << 1].bit[i] + t[(v << 1) | 1].bit[i];
  return;
}
long long get_sum(int l, int r, int v = 1, int tl = 0, int tr = sz) {
  if (r < l || t[v].Re == -1) return 0LL;
  push(v, (tr - tl + 1) >> 1);
  if (tl == l && tr == r) {
    long long sum(0LL);
    for (int i(0); i < 20; ++i) sum += ((long long)t[v].bit[i]) << i;
    return sum;
  }
  int tm((tr + tl) >> 1);
  return get_sum(l, min(tm, r), v << 1, tl, tm) +
         get_sum(max(tm + 1, l), r, (v << 1) | 1, tm + 1, tr);
}
long long ans;
void solve() {
  read(m);
  int type, l, r, x;
  while (m--) {
    read(type);
    read(l);
    read(r);
    l--, r--;
    if (type == 1) {
      ans = get_sum(l, r);
      write(ans);
    } else {
      read(x);
      update(l, r, x);
    }
  }
}
void start() {
  read(n);
  int i(0);
  for (; i < n; ++i) read(a[i]);
  for (sz = 1; sz < n; sz <<= 1)
    ;
  sz--;
  build();
  return;
}
int main() {
  start();
  solve();
  return 0;
}
