#include <bits/stdc++.h>
const int MaxBits = 31;
struct Node {
  Node *left = nullptr, *right;
  int from, to, update = 0, bitcount[MaxBits];
  Node(int from, int to) : from(from), to(to) {
    std::fill_n(bitcount, MaxBits, 0);
  }
  ~Node() {
    if (left) delete left, delete right;
  }
  void makeKidsAndUpdate() {
    if (from < to && !left) {
      long long middle = (from + to) >> 1;
      left = new Node(from, middle);
      right = new Node(middle + 1, to);
    }
    if (from < to) left->update ^= update, right->update ^= update;
    for (long long i = 0; i < MaxBits; ++i)
      if (update & (1 << i)) bitcount[i] = to + 1 - from - bitcount[i];
    update = 0;
  }
  void insert(int a, int b, int value) {
    makeKidsAndUpdate();
    if (from >= a && to <= b)
      update ^= value;
    else {
      if (a <= left->to) left->insert(a, b, value);
      if (b >= right->from) right->insert(a, b, value);
      left->makeKidsAndUpdate();
      right->makeKidsAndUpdate();
      for (long long i = 0; i < MaxBits; ++i)
        bitcount[i] = left->bitcount[i] + right->bitcount[i];
    }
  }
  long long sum(int a, int b) {
    makeKidsAndUpdate();
    long long result = 0;
    if (from >= a && to <= b)
      for (long long i = 0; i < MaxBits; ++i)
        result += bitcount[i] * (1LL << i);
    else {
      if (a <= left->to) result += left->sum(a, b);
      if (b >= right->from) result += right->sum(a, b);
      left->makeKidsAndUpdate();
      right->makeKidsAndUpdate();
      for (long long i = 0; i < MaxBits; ++i)
        bitcount[i] = left->bitcount[i] + right->bitcount[i];
    }
    return result;
  }
} root{0, int(1e5 + 1)};
int main() {
  int n, m, t, a, b, x;
  scanf("%d", &n);
  for (long long i = 0; i < n; ++i)
    scanf("%d", &x), root.insert(i + 1, i + 1, x);
  scanf("%d", &m);
  while (m--) {
    scanf("%d%d%d", &t, &a, &b);
    if (t == 1)
      printf("%I64d\n", root.sum(a, b));
    else
      scanf("%d", &x), root.insert(a, b, x);
  }
}
