#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ft first
#define sd second
#define VI vector<int>
#define VLL vector<long long int>
#define PII pair<int,int>
#define pb push_back
#define rsz(v,n) v.resize(n)
// input and output
#define scan(x) scanf("%d",&x)
#define scanll(x) scanf("%lld",&x)
#define ll long long int
#define rep(i,x,y) for(i=x;i<y;i++)
#define print(x) printf("%d\n",x)
#define printll(x) printf("%lld\n",x)
#define all(v) v.begin(),v.end()
#define ms(v) memset(v,0,sizeof(v))
#define FOR(i,a,b) for(i=a;i<b;i++)
struct node{
int bit[22];
bool bit_mask[22];
bool flag;
ll sum;
int count;
node(){
memset(bit,0,sizeof(bit));
memset(bit_mask,0,sizeof(bit_mask));
sum=0;
flag=0;
}
};
vector<node>st;
VI arr;
void buildst(int idx,int ss,int se){
if(ss==se){
for(int i=0;i<21;i++)
{
if(((1<<i)&arr[se]))
st[idx].bit[i]=true;
else
st[idx].bit[i]=false;
}
return;
}
int mid=(ss+se)>>1;
buildst(2*idx+1,ss,mid);
buildst(2*idx+2,mid+1,se);
for(int i=0;i<=21;i++) st[idx].bit[i]=st[idx*2+1].bit[i]+st[idx*2+2].bit[i];
}
void adjust(int idx,int ss,int se){
int mid=(ss+se)>>1;
for(int i=0;i<=21;i++)
{
int x=st[idx].bit_mask[i];
if(x){
st[2*idx+1].bit[i]=mid-ss+1-st[2*idx+1].bit[i];
if(st[idx*2+1].bit_mask[i]){
st[idx*2+1].bit_mask[i]=0;
}else{
st[idx*2+1].bit_mask[i]=1;
}
}else{
if(st[idx*2+1].bit_mask[i]){
st[idx*2+1].bit_mask[i]=1;
}else{
st[idx*2+1].bit_mask[i]=0;
}
}
if(x){
st[2*idx+2].bit[i]=se-mid-st[2*idx+2].bit[i];
if(st[idx*2+2].bit_mask[i]){
st[idx*2+2].bit_mask[i]=0;
}else{
st[idx*2+2].bit_mask[i]=1;
}
}else{
if(st[idx*2+2].bit_mask[i]){
st[idx*2+2].bit_mask[i]=1;
}else{
st[idx*2+2].bit_mask[i]=0;
}
}
}
st[idx*2+1].flag=1;
st[idx*2+2].flag=1;
st[idx].flag=0;
for(int i=0;i<=21;i++) st[idx].bit_mask[i]=0;
}
void update(int idx,int ss,int se,int l,int r,int x)
{
if(ss>r||l>se) return;
if(l<=ss&&se<=r){
for(int i=0;i<=21;i++){
if(x&(1<<i)){
st[idx].bit[i]=se-ss+1-st[idx].bit[i];
if(st[idx].bit_mask[i]){
st[idx].bit_mask[i]=0;
}else{
st[idx].bit_mask[i]=1;
}
}else{
if(st[idx].bit_mask[i]){
st[idx].bit_mask[i]=1;
}else{
st[idx].bit_mask[i]=0;
}
}
}
st[idx].flag=true;
return;
}
int mid=(ss+se)>>1;
if(st[idx].flag) adjust(idx,ss,se);
update(2*idx+1,ss,mid,l,r,x);
update(2*idx+2,mid+1,se,l,r,x);
for(int i=0;i<=21;i++) st[idx].bit[i]=st[idx*2+1].bit[i]+st[idx*2+2].bit[i];
}
ll query(int idx,int ss,int se,int l,int r)
{
if(l>se||r<ss) return 0;
ll sum;
if(l<=ss&&se<=r)
{
sum=0;
for(int i=0;i<=21;i++)
sum+=((1<<i)*st[idx].bit[i]);
return sum;
}
if(st[idx].flag) adjust(idx,ss,se);
int mid=(ss+se)>>1;
return query(2*idx+1,ss,mid,l,r)+query(2*idx+2,mid+1,se,l,r);
}
int main()
{
int n;
scan(n);
int size=(ceil)(log2(n))+1;
size++;
st.resize(1<<size);
arr.resize(n);
for(int i=0;i<n;i++) cin>>arr[i];
buildst(0,0,n-1);
int q;
scan(q);
int l,r,x,type;
while(q--)
{
scan(type);
scan(l);
scan(r);
l--;
r--;
if(type==2){
scan(x);
update(0,0,n-1,l,r,x);
}else{
cout<<query(0,0,n-1,l,r)<<endl;
}
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKI2R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