#include <bits/stdc++.h>
using namespace std;
const int MAX_LOG = 20;
struct node {
  int l, r, lazy;
  vector<int> val;
  node *left, *right;
};
vector<int> add(const vector<int> &a, const vector<int> &b) {
  vector<int> c(MAX_LOG + 1);
  for (int i = 0; i <= MAX_LOG; i++) c[i] = a[i] + b[i];
  return move(c);
}
node *build(int l, int r, const vector<int> &a) {
  if (l == r) {
    vector<int> val(MAX_LOG + 1, 0);
    for (int i = 0; i <= MAX_LOG; i++)
      if (a[l] & (1 << i)) val[i] = 1;
    return new node{l, r, 0, val, nullptr, nullptr};
  }
  node *left = build(l, (l + r) / 2, a);
  node *right = build((l + r) / 2 + 1, r, a);
  return new node{l, r, 0, add(left->val, right->val), left, right};
}
void propagate(node *cur) {
  for (int i = 0; i <= MAX_LOG; i++)
    if (cur->lazy & (1 << i)) cur->val[i] = (cur->r - cur->l + 1) - cur->val[i];
  if (cur->left != nullptr) {
    cur->left->lazy ^= cur->lazy;
    cur->right->lazy ^= cur->lazy;
  }
  cur->lazy = 0;
}
vector<int> query(node *cur, int l, int r) {
  propagate(cur);
  if (cur->l > r || cur->r < l) return vector<int>(MAX_LOG + 1, 0);
  if (l <= cur->l && cur->r <= r) return cur->val;
  return add(query(cur->left, l, r), query(cur->right, l, r));
}
void update(node *cur, int l, int r, int x) {
  propagate(cur);
  if (cur->l > r || cur->r < l) return;
  if (l <= cur->l && cur->r <= r) {
    cur->lazy = x;
    propagate(cur);
    return;
  }
  update(cur->left, l, r, x);
  update(cur->right, l, r, x);
  cur->val = add(cur->left->val, cur->right->val);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  node *root = build(0, n - 1, a);
  int q;
  cin >> q;
  while (q--) {
    int t, l, r, x;
    cin >> t >> l >> r;
    if (t == 1) {
      vector<int> val = query(root, l - 1, r - 1);
      long long ans = 0;
      for (int i = 0; i <= MAX_LOG; i++) ans += (1ll << i) * val[i];
      cout << ans << '\n';
    } else {
      cin >> x;
      update(root, l - 1, r - 1, x);
    }
  }
  return 0;
}
