//In the name of God
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct node
{
  node *l,*r;
  int st,en;
  int val;
  bool revch;
  node(int x,int y)
  {
    st=x;
    en=y;
  }
  void change(int begin,int end)
  {
    begin=max(begin,st);
    end=min(end,en);
    if(begin>end) return;
    if(begin==st and end==en)
      {
    revch=1-revch;
	val=(en-st+1)-val;
      }
    else if(st!=en)
      {
	if(l==NULL)
	  l=new node(st,(st+en)/2);
	l->change(begin,end);
	if(r==NULL)
	  r=new node((st+en)/2+1,en);
	r->change(begin,end);
	val=l->val+r->val;
	if(revch)
	  val=(en-st+1)-val;
      }
  }
  int query(int begin,int end)
  {
    begin=max(begin,st);
    end=min(end,en);
    if(begin>end) return 0;
    if(begin==st and end==en)
      return val;
    else if(st!=en)
      {
	int sum=0;
	if(l!=NULL)
	sum+=l->query(begin,end);
	if(r!=NULL)
	sum+=r->query(begin,end);
	if(revch)
	  sum=(end-begin+1)-sum;
	return sum;
      }
    return 0;
  }
};

int main()
{
  vector<node *> st(20);
  for(int i=0;i<st.size();++i)
    st[i]=new node(0,1e5+10);
  int n;
  cin>>n;
  for(int i=1;i<=n;++i)
    {
      int a; cin>>a;
      for(int j=0;a!=0;j++)
	{
	  if(a%2)
	    st[j]->change(i,i);
	  a/=2;
	}
    }
  int m;
  cin>>m;
  while(m--)
    {
      int t,sst,en,xo;
      cin>>t>>sst>>en;
      if(t==1)
	{
	  //sum
	  int ans=0;
	  for(int j=0;j<st.size();++j)
	    {
	      int c=st[j]->query(sst,en);
	      c<<=j;
	      ans+=c;
	    }
	  cout<<fixed<<ans<<endl;
	}
      else
	{
	  cin>>xo;
	  for(int j=0;xo!=0;j++)
	    {
	      if(xo%2)
		st[j]->change(sst,en);
	      xo/=2;
	    }
	}
    }
  return 0;
}