#include<iostream>
using namespace std;

int x, y, z, p, n, m;

int main(){
	cin >> n >> m >> x >> y >> z >> p;
	int i, j, ni, nj;
	x %= 4;
	y %= 2;
	z %= 4;
	while (p--){
		cin >> i >> j;
		for (int k = 0; k < x; k++){
			ni = j;
			nj = m - i + 1;
			i = ni; j = nj;
		}
		for (int k = 0; k < y; k++){
			j = n - j + 1;
		}
		for (int k = 0; k < z; k++){
			ni = m - j + 1;
			nj = i;
			i = ni; j = nj;
		}
		cout << i << " " << j << endl;
	}
	return 0;
}


#include<iostream>
using namespace std;

long long int x, y, z, p, n, m;

int main(){
	cin >> n >> m >> x >> y >> z >> p;
	int i, j, ni, nj, u, v;
	x %= 4;
	y %= 2;
	z *= 3;
	z %= 4;
	u = n; v = m;
	while (p--){
		cin >> i >> j;
		n = u; m = v;
		for (int k = 0; k < x; k++){
			ni = j;
			nj = n - i + 1;
			i = ni; j = nj;
			swap(n, m);
		}
		for (int k = 0; k < y; k++){
			j = m - j + 1;
		}
		for (int k = 0; k < z; k++){
			nj = n - i + 1;
			ni = j;
			i = ni; j = nj;
			swap(n, m);
		}
		cout << i << " " << j << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define pb push_back
#define e1 first
#define e2 second
#define tysiac 1010
#define milion 1000100
#define OUT(x) { cout << x; return 0; }
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <ld, ld> PDD;
typedef pair <PII, PII> PP;
typedef pair <ll, int> PLI;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int MOD = 1e9+696969;
int n,m,x,y,z, i, j;
void RROTATE(int &i, int &j)
{
    int x = i, y = j;
    i = y;
    j = n - x + 1;
    swap(n, m);
}
void HROTATE(int &i, int &j)
{
    j = m - j + 1;
}
int main()
{
    int T;
    scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &T);
    x = x % 4;
    z = z % 4;
    y = y & 1;
    while (T--)
    {
        scanf("%d%d", &i, &j);
        for (int help = 0; help < x; ++help) RROTATE(i, j);
        if (y) HROTATE(i, j);
        for (int help = 0; help < (4 - z); ++help) RROTATE(i, j);
        printf("%d %d\n", i, j);
    }
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define pb push_back
#define e1 first
#define e2 second
#define tysiac 1010
#define milion 1000100
#define OUT(x) { cout << x; return 0; }
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <ld, ld> PDD;
typedef pair <PII, PII> PP;
typedef pair <ll, int> PLI;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int MOD = 1e9+696969;
int n,m,x,y,z, i, j, N, M;
void RROTATE(int &i, int &j)
{
    int x = i, y = j;
    i = y;
    j = N - x + 1;
    swap(N, M);
}
void HROTATE(int &i, int &j)
{
    j = m - j + 1;
}
int main()
{
    int T;
    scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &T);
    x = x % 4;
    z = z % 4;
    y = y & 1;
    while (T--)
    {
        N = n; M = m;
        scanf("%d%d", &i, &j);
        for (int help = 0; help < x; ++help) RROTATE(i, j);
        if (y) HROTATE(i, j);
        for (int help = 0; help < (4 - z); ++help) RROTATE(i, j);
        printf("%d %d\n", i, j);
    }
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define pb push_back
#define e1 first
#define e2 second
#define tysiac 1010
#define milion 1000100
#define OUT(x) { cout << x; return 0; }
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <ld, ld> PDD;
typedef pair <PII, PII> PP;
typedef pair <ll, int> PLI;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int MOD = 1e9+696969;
int n,m,x,y,z, i, j, N, M;
void RROTATE(int &i, int &j)
{
    int x = i, y = j;
    i = y;
    j = N - x + 1;
    swap(N, M);
}
void HROTATE(int &i, int &j)
{
    j = M - j + 1;
}
int main()
{
    int T;
    scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &T);
    x = x % 4;
    z = z % 4;
    y = y & 1;
    while (T--)
    {
        N = n; M = m;
        scanf("%d%d", &i, &j);
        for (int help = 0; help < x; ++help) RROTATE(i, j);
        if (y) HROTATE(i, j);
        for (int help = 0; help < (4 - z); ++help) RROTATE(i, j);
        printf("%d %d\n", i, j);
    }
}


#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define pb push_back
#define e1 first
#define e2 second
#define tysiac 1010
#define milion 1000100
#define OUT(x) { cout << x; return 0; }
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <ld, ld> PDD;
typedef pair <PII, PII> PP;
typedef pair <ll, int> PLI;
const int mod = 1e9+7;
const int inf = 1e9+9;
const int MOD = 1e9+696969;
int n,m,x,y,z, i, j;
void RROTATE(int &i, int &j)
{
	int x = i, y = j;
	i = y;
	j = n - x + 1;
}
void HROTATE(int &i, int &j)
{
	j = m - j + 1;
}
int main()
{
	int T;
	scanf("%d%d%d%d%d%d", &n, &m, &x, &y, &z, &T);
	x = x % 4;
	z = z % 4;
	y = y & 1;
	while (T--)
	{
		scanf("%d%d", &i, &j);
		for (int help = 0; help < x; ++help) RROTATE(i, j);
		if (y) HROTATE(i, j);
		for (int help = 0; help < (4 - z); ++help) RROTATE(i, j);
		printf("%d %d\n", i, j);
	}
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = 123456;
int x[N] , y[N];
int X,Y,Z,n,m,p;
void change_x(){
	if(X == 1){
		for(int i = 0; i < p; i++){
			int a = x[i] , b = y[i];
			x[i] = b;
			y[i] = n - a + 1;
		}
		swap(n,m);
	}
	else if(X == 2){
		for(int i = 0; i < p; i++){
			int a = x[i] , b = y[i];
			x[i] = n - a + 1;
			y[i] = m - b + 1;
		}
	}
	else if(X == 3){
		for(int i = 0; i < p; i++){
			int a = x[i], b = y[i];
			x[i] = m - b + 1;
			y[i] = a;
		}
		swap(n,m);
	}
}

void change_y(){
	if(Y == 1){
		for(int i = 0; i < p; i++){
				y[i] = m + 1- y[i];
			}
	}
}

void change_z(){
	if(Z == 1){
		for(int i = 0; i < p; i++){
			int a = x[i] , b = y[i];
			x[i] = m - b +1;
			y[i] = a;
		}
		swap(n,m);
	}
	else if(Z == 2){
		for(int i = 0; i < p; i++){
			int a = x[i],b = y[i];
			x[i] = n - a + 1;
			y[i] = m - b + 1;
		}
	}
	else if(Z == 3){
		for(int i = 0; i < p; i++){
			int a = x[i], b = y[i];
			x[i] = b;
			y[i] = n - a + 1;
		}
	}
}

int main(){
	cin>>n>>m>>X>>Y>>Z>>p;
	for(int i = 0; i < p; i++)
		cin>>x[i]>>y[i];
	X = X%4;
	Y = Y%2;
	Z = Z%4;
	change_x();
	change_y();
	change_z();
	for(int i = 0; i < p; i++)
		cout<<x[i]<<" "<<y[i]<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = 123456;
int x[N] , y[N];
int X,Y,Z,n,m,p;
void change_x(){
	if(X == 1){
		for(int i = 0; i < p; i++){
			int a = x[i] , b = y[i];
			x[i] = b;
			y[i] = n - a + 1;
		}
		swap(n,m);
	}
	else if(X == 2){
		for(int i = 0; i < p; i++){
			int a = x[i] , b = y[i];
			x[i] = n - a + 1;
			y[i] = m - b + 1;
		}
	}
	else if(X == 3){
		for(int i = 0; i < p; i++){
			int a = x[i], b = y[i];
			x[i] = m - b + 1;
			y[i] = a;
		}
		swap(n,m);
	}
}

void change_y(){
	if(Y == 1){
		for(int i = 0; i < p; i++){
				y[i] = m + 1- y[i];
			}
	}
}

void change_z(){
	if(Z == 1){
		for(int i = 0; i < p; i++){
			int a = x[i] , b = y[i];
			x[i] = m - b +1;
			y[i] = a;
		}
		swap(n,m);
	}
	else if(Z == 2){
		for(int i = 0; i < p; i++){
			int a = x[i],b = y[i];
			x[i] = n - a + 1;
			y[i] = m - b + 1;
		}
	}
	else if(Z == 3){
		for(int i = 0; i < p; i++){
			int a = x[i], b = y[i];
			x[i] = b;
			y[i] = n - a + 1;
		}
	}
}

int main(){
	cin>>n>>m>>X>>Y>>Z>>p;
	for(int i = 0; i < p; i++)
		cin>>x[i]>>y[i];
	X = X%4;
	Y = Y%4;
	Z = Z%4;
	change_x();
	change_y();
	change_z();
	for(int i = 0; i < p; i++)
		cout<<x[i]<<" "<<y[i]<<endl;
	return 0;
}


#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
const int N = 123456;
int x[N] , y[N];
int X,Y,Z,n,m,p;
void change_x(){
	if(X == 1){
		for(int i = 0; i < p; i++){
			int a = x[i] , b = y[i];
			x[i] = b;
			y[i] = n - a + 1;
		}
		swap(n,m);
	}
	else if(X == 2){
		for(int i = 0; i < p; i++){
			int a = x[i] , b = y[i];
			x[i] = n - a + 1;
			y[i] = m - b + 1;
		}
	}
	else if(X == 3){
		for(int i = 0; i < p; i++){
			int a = x[i], b = y[i];
			x[i] = m - b + 1;
			y[i] = a;
		}
		swap(n,m);
	}
}

void change_y(){
	if(Y == 1){
		if(m%2 == 1){
			for(int i = 0; i < p; i++){
				y[i] = m + 1 - y[i];
			}
		}
		else {
			for(int i = 0; i < p; i++){
				y[i] = m - y[i];
			}
		}
	}
}

void change_z(){
	if(Z == 1){
		for(int i = 0; i < p; i++){
			int a = x[i] , b = y[i];
			x[i] = m - b +1;
			y[i] = a;
		}
		swap(n,m);
	}
	else if(Z == 2){
		for(int i = 0; i < p; i++){
			int a = x[i],b = y[i];
			x[i] = n - a + 1;
			y[i] = m - b + 1;
		}
	}
	else if(Z == 3){
		for(int i = 0; i < p; i++){
			int a = x[i], b = y[i];
			x[i] = b;
			y[i] = n - a + 1;
		}
	}
}

int main(){
	cin>>n>>m>>X>>Y>>Z>>p;
	for(int i = 0; i < p; i++)
		cin>>x[i]>>y[i];
	X = X%4;
	Y = Y%4;
	Z = Z%4;
	change_x();
	change_y();
	change_z();
	for(int i = 0; i < p; i++)
		cout<<x[i]<<" "<<y[i]<<endl;
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <ratio>
#include <regex>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <valarray>

using namespace std;

#define sz(v) (int)v.size()
#define eps 1e-10
#define all(v) v.begin(), v.end()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))
#define in(v, x) (find(all(v),x) != v.end())
#define re return
#define sum(v) accumulate(v.begin(),v.end(),(ld)0)
#define tr(v,it) for(auto it=v.begin();it != v.end();it++)
#define asrt(v) sort(v.begin(),v.end())
#define dsrt(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define pi 3.1415926535897932384626433832795
#define MOD 1000000007
#define print(v) for (auto& i:v) cout<<i<<endl
#define endl '\n'

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<vi> vvi;

#define N 100000+5

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout<<setprecision(15);
#ifndef ONLINE_JUDGE
	freopen("Data/input.txt", "r", stdin);
	freopen("Data/output.txt", "w", stdout);
#endif
	int n,m,x,y,z,p,a,b;
	cin>>n>>m>>x>>y>>z>>p;
	x%=4;
	y%=2;
	z%=4;
	for(int i=0; i<p; i++) {
		cin>>a>>b;
		int r=n,c=m;
		for(int j=0; j<x; j++) {
			int aa=a,bb=b;
			a=bb;
			b=r-aa+1;
			swap(r,c);
		}
		r=n,c=m;
		for(int j=0; j<y; j++) {
			int aa=a,bb=b;
			a=aa;
			b=c-bb+1;
		}
		r=n,c=m;
		for(int j=0; j<z; j++) {
			int aa=a,bb=b;
			a=c-bb+1;
			b=aa;
			swap(r,c);
		}
		cout<<a<<" "<<b<<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <ratio>
#include <regex>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <valarray>

using namespace std;

#define sz(v) (int)v.size()
#define eps 1e-10
#define all(v) v.begin(), v.end()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))
#define in(v, x) (find(all(v),x) != v.end())
#define re return
#define sum(v) accumulate(v.begin(),v.end(),(ld)0)
#define tr(v,it) for(auto it=v.begin();it != v.end();it++)
#define asrt(v) sort(v.begin(),v.end())
#define dsrt(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define pi 3.1415926535897932384626433832795
#define MOD 1000000007
#define print(v) for (auto& i:v) cout<<i<<endl
#define endl '\n'

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<vi> vvi;

#define N 100000+5

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout<<setprecision(15);
#ifndef ONLINE_JUDGE
	freopen("Data/input.txt", "r", stdin);
	freopen("Data/output.txt", "w", stdout);
#endif
	int n,m,x,y,z,p,a,b;
	cin>>n>>m>>x>>y>>z>>p;
	x%=4;
	y%=2;
	z%=4;
	for(int i=0; i<p; i++) {
		cin>>a>>b;
		for(int j=0; j<x; j++) {
			int aa=a,bb=b;
			a=bb;
			b=n-aa+1;
		}
		for(int j=0; j<y; j++) {
			int aa=a,bb=b;
			a=aa;
			b=m-bb+1;
		}
		for(int j=0; j<z; j++) {
			int aa=a,bb=b;
			a=m-bb+1;
			b=aa;
		}
		cout<<a<<" "<<b<<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <ratio>
#include <regex>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <valarray>

using namespace std;

#define sz(v) (int)v.size()
#define eps 1e-10
#define all(v) v.begin(), v.end()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))
#define in(v, x) (find(all(v),x) != v.end())
#define re return
#define sum(v) accumulate(v.begin(),v.end(),(ld)0)
#define tr(v,it) for(auto it=v.begin();it != v.end();it++)
#define asrt(v) sort(v.begin(),v.end())
#define dsrt(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define pi 3.1415926535897932384626433832795
#define MOD 1000000007
#define print(v) for (auto& i:v) cout<<i<<endl
#define endl '\n'

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<vi> vvi;

#define N 100000+5

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout<<setprecision(15);
#ifndef ONLINE_JUDGE
	freopen("Data/input.txt", "r", stdin);
	freopen("Data/output.txt", "w", stdout);
#endif
	int n,m,x,y,z,p,a,b;
	cin>>n>>m>>x>>y>>z>>p;
	x%=4;
	y%=4;
	z%=4;
	for(int i=0; i<p; i++) {
		cin>>a>>b;
		for(int j=0; j<x; j++) {
			int aa=a,bb=b;
			a=bb;
			b=n-aa+1;
		}
		for(int j=0; j<y; j++) {
			int aa=a,bb=b;
			a=aa;
			b=m-bb+1;
		}
		for(int j=0; j<z; j++) {
			int aa=a,bb=b;
			a=m-bb+1;
			b=aa;
		}
		cout<<a<<" "<<b<<endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <cctype>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <fstream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <numeric>
#include <ratio>
#include <regex>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <valarray>

using namespace std;

#define sz(v) (int)v.size()
#define eps 1e-10
#define all(v) v.begin(), v.end()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a) memset(a,-1,sizeof(a))
#define chk(a,k) ((bool)(a&(1<<(k))))
#define set0(a,k) (a&(~(1<<(k))))
#define set1(a,k) (a|(1<<(k)))
#define in(v, x) (find(all(v),x) != v.end())
#define re return
#define sum(v) accumulate(v.begin(),v.end(),(ld)0)
#define tr(v,it) for(auto it=v.begin();it != v.end();it++)
#define asrt(v) sort(v.begin(),v.end())
#define dsrt(v) sort(v.rbegin(),v.rend())
#define rev(v) reverse(v.begin(),v.end())
#define pi 3.1415926535897932384626433832795
#define MOD 1000000007
#define print(v) for (auto& i:v) cout<<i<<endl
#define endl '\n'

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<string> vs;
typedef vector<vi> vvi;

#define N 100000+5

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout<<setprecision(15);
#ifndef ONLINE_JUDGE
	freopen("Data/input.txt", "r", stdin);
	freopen("Data/output.txt", "w", stdout);
#endif
	int n,m,x,y,z,p,a,b;
	cin>>n>>m>>x>>y>>z>>p;
	x%=4;
	y%=2;
	z%=4;
	for(int i=0; i<p; i++) {
		cin>>a>>b;
		int r=n,c=m;
		for(int j=0; j<x; j++) {
			int aa=a,bb=b;
			a=bb;
			b=r-aa+1;
			swap(r,c);
		}
		for(int j=0; j<y; j++) {
			int aa=a,bb=b;
			a=aa;
			b=c-bb+1;
		}
		for(int j=0; j<z; j++) {
			int aa=a,bb=b;
			a=c-bb+1;
			b=aa;
			swap(r,c);
		}
		cout<<a<<" "<<b<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace::std;

#define ll  long long
#define ull unsigned ll
#define LD long double

#define mp make_pair
#define bs binary_search
#define gcd __gcd
#define pb push_back
#define pp pop_back
#define ff first
#define ss second

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define rf freopen("input.txt","r",stdin)
#define wf freopen("output.txt","w",stdout)

#define Nitro \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)

#define sz(a) (int)a.size()

int main()
{
      ll N,M,x,y,z,p;
      ll xi,yi;

      cin >> N >> M;
      cin >> x >> y >> z;
      cin >> p;
      vector< pair<ll,ll> > Vec;
      for(ll i=0;i<p;i++){
                  cin >> xi >> yi;
                  Vec.pb(mp(xi,yi));
      }
      x = x%4;
      y = y%2;
      z = z%4;
      for(ll i=0;i<x;i++){
            for(ll j=0;j<p;j++){
                  ll x1 = Vec[j].ff;
                  ll y1 = Vec[j].ss;
                  Vec[j].ff = y1;
                  Vec[j].ss = N+1 - x1;
            }
            swap(N,M);
      }
      /*
      cout << "X ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
      */
      for(ll i=0;i<y;i++){
            for(ll j=0;j<p;j++){
                  ll x1 = Vec[j].ff;
                  ll y1 = Vec[j].ss;
                  Vec[j].ff = x1;
                  Vec[j].ss = M+1-y1;
            }
      }
      /*
      cout << "Y ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
      */
      for(ll i=0;i<4-z;i++){
            for(ll j=0;j<p;j++){
                  ll x1 = Vec[j].ff;
                  ll y1 = Vec[j].ss;
                  Vec[j].ff = y1;
                  Vec[j].ss = N+1 - x1;
            }
            swap(N,M);
      }
      /*
      cout << "Z ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }

      cout << endl;
      */
      for(ll i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
	return 0;
}


#include<bits/stdc++.h>
using namespace::std;

#define ll  long long
#define ull unsigned ll
#define LD long double

#define mp make_pair
#define bs binary_search
#define gcd __gcd
#define pb push_back
#define pp pop_back
#define ff first
#define ss second

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define rf freopen("input.txt","r",stdin)
#define wf freopen("output.txt","w",stdout)

#define Nitro \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)

#define sz(a) (int)a.size()

int main()
{
      ll N,M,x,y,z,p;
      ll xi,yi;

      cin >> N >> M;
      cin >> x >> y >> z;
      cin >> p;
      vector< pair<ll,ll> > Vec;
      for(ll i=0;i<p;i++){
                  cin >> xi >> yi;
                  Vec.pb(mp(xi,yi));
      }
      x = x%4;
      y = y%2;
      z = z%4;
      for(ll i=0;i<x;i++){
            for(ll j=0;j<p;j++){
                  ll x1 = Vec[j].ff;
                  ll y1 = Vec[j].ss;
                  Vec[j].ff = y1;
                  Vec[j].ss = M+1 - x1;
            }
            swap(N,M);
      }
      /*
      cout << "X ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
      */
      for(ll i=0;i<y;i++){
            for(ll j=0;j<p;j++){
                  int x1 = Vec[j].ff;
                  int y1 = Vec[j].ss;
                  Vec[j].ff = x1;
                  Vec[j].ss = M+1-y1;
            }
      }
      /*
      cout << "Y ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
      */
      for(ll i=0;i<4-z;i++){
            for(ll j=0;j<p;j++){
                  ll x1 = Vec[j].ff;
                  ll y1 = Vec[j].ss;
                  Vec[j].ff = y1;
                  Vec[j].ss = M+1 - x1;
            }
            swap(N,M);
      }
      /*
      cout << "Z ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }

      cout << endl;
      */
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
	return 0;
}


#include<bits/stdc++.h>
using namespace::std;

#define ll  long long
#define ull unsigned ll
#define LD long double

#define mp make_pair
#define bs binary_search
#define gcd __gcd
#define pb push_back
#define pp pop_back
#define ff first
#define ss second

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define rf freopen("input.txt","r",stdin)
#define wf freopen("output.txt","w",stdout)

#define Nitro \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)

#define sz(a) (int)a.size()

int main()
{
      ll N,M,x,y,z,p;
      ll xi,yi;

      cin >> N >> M;
      cin >> x >> y >> z;
      cin >> p;
      vector< pair<ll,ll> > Vec;
      for(ll i=0;i<p;i++){
                  cin >> xi >> yi;
                  Vec.pb(mp(xi,yi));
      }
      x = x%4;
      y = y%2;
      z = z%4;
      for(ll i=0;i<x;i++){
            for(ll j=0;j<p;j++){
                  ll x1 = Vec[j].ff;
                  ll y1 = Vec[j].ss;
                  Vec[j].ff = y1;
                  Vec[j].ss = M+1 - x1;
            }
            swap(N,M);
      }
      /*
      cout << "X ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
      */
      for(ll i=0;i<y;i++){
            for(ll j=0;j<p;j++){
                  ll x1 = Vec[j].ff;
                  ll y1 = Vec[j].ss;
                  Vec[j].ff = x1;
                  Vec[j].ss = M+1-y1;
            }
      }
      /*
      cout << "Y ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
      */
      for(ll i=0;i<4-z;i++){
            for(ll j=0;j<p;j++){
                  ll x1 = Vec[j].ff;
                  ll y1 = Vec[j].ss;
                  Vec[j].ff = y1;
                  Vec[j].ss = M+1 - x1;
            }
            swap(N,M);
      }
      /*
      cout << "Z ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }

      cout << endl;
      */
      for(ll i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
	return 0;
}


#include<bits/stdc++.h>
using namespace::std;

#define ll  long long
#define ull unsigned ll
#define LD long double

#define mp make_pair
#define bs binary_search
#define gcd __gcd
#define pb push_back
#define pp pop_back
#define ff first
#define ss second

#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

#define rf freopen("input.txt","r",stdin)
#define wf freopen("output.txt","w",stdout)

#define Nitro \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)

#define sz(a) (int)a.size()

int main()
{
      int N,M,x,y,z,p;
      int xi,yi;

      cin >> N >> M;
      cin >> x >> y >> z;
      cin >> p;
      vector< pair<int,int> > Vec;
      for(int i=0;i<p;i++){
                  cin >> xi >> yi;
                  Vec.pb(mp(xi,yi));
      }
      x = x%4;
      y = y%2;
      z = z%4;
      for(int i=0;i<x;i++){
            for(int j=0;j<p;j++){
                  int x1 = Vec[j].ff;
                  int y1 = Vec[j].ss;
                  Vec[j].ff = y1;
                  Vec[j].ss = M+1 - x1;
            }
            swap(N,M);
      }
      /*
      cout << "X ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
      */
      for(int i=0;i<y;i++){
            for(int j=0;j<p;j++){
                  int x1 = Vec[j].ff;
                  int y1 = Vec[j].ss;
                  Vec[j].ff = x1;
                  Vec[j].ss = M+1-y1;
            }
      }
      /*
      cout << "Y ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
      */
      for(int i=0;i<4-z;i++){
            for(int j=0;j<p;j++){
                  int x1 = Vec[j].ff;
                  int y1 = Vec[j].ss;
                  Vec[j].ff = y1;
                  Vec[j].ss = M+1 - x1;
            }
            swap(N,M);
      }
      /*
      cout << "Z ROTATE \n" << endl;
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }

      cout << endl;
      */
      for(int i=0;i<p;i++){
            cout << Vec[i].ff << " " << Vec[i].ss << endl;
      }
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define forn(i,n) for (int i=0;i<(int)(n);i++)
#define forsn(i,s,n) for (int i=(s);i<(int)(n);i++)
#define dforn(i,n) for(int i=(int)((n)-1);i>=0;i--)
#define dforsn(i,s,n) for(int i=(int)((n)-1);i>=(int)(s);i--)
#define all(c) (c).begin(),(c).end()
#define esta(x,c) ((c).find(x) != (c).end())
#define dbg(x) cerr << #x << " = " << (x) << endl
#define raya cerr << "----------" << endl
#define wbe(f, c, as...) f(all(c), ##as)
#define wbeb(f, c, d, as...) f(all(c), (d).begin() ##as)
#define L(r, as...) [](as){return r;}

#ifdef ACMTUYO
#define LEA freopen("in.txt", "r", stdin)
#else
#define LEA
#endif

// TYPEDEFS

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double tdbl;

#define mp make_pair
#define pb push_back

const double PI=acos(-1.0);

const int MAXP = 1e5+5;
int h, w, x, y, z, p;
int ch[MAXP], cw[MAXP];

void rotate(){
	swap(h,w);
	forn(i,p){
		swap(ch[i], cw[i]);
		ch[i] = h-ch[i]-1;
	}
}

void mirror(){
	forn(i,p){
		cw[i] = w-cw[i]-1;
	}
}

int main(int argc, char **argv) {

	LEA;

	ios_base::sync_with_stdio(0);

	cin >> h >> w >> x >> y >> z >> p;

	forn(i,p){
		int a, b;
		cin >> a >> b;
		ch[i]=a-1;
		cw[i]=b-1;
	}

//	forn(i,p) cerr << cx[i] << ", " << cy[i] << "      ";

	//cerr << endl;

	forn(i, x*3%4) rotate();
	if(y%2) mirror();
	forn(i, z%4) rotate();

	forn(i,p){
			cout << ch[i] + 1 << " " << cw[i] + 1 << "\n";
	}
	cout << flush;

}


#include <bits/stdc++.h>

using namespace std;

#define forn(i,n) for (int i=0;i<(int)(n);i++)
#define forsn(i,s,n) for (int i=(s);i<(int)(n);i++)
#define dforn(i,n) for(int i=(int)((n)-1);i>=0;i--)
#define dforsn(i,s,n) for(int i=(int)((n)-1);i>=(int)(s);i--)
#define all(c) (c).begin(),(c).end()
#define esta(x,c) ((c).find(x) != (c).end())
#define dbg(x) cerr << #x << " = " << (x) << endl
#define raya cerr << "----------" << endl
#define wbe(f, c, as...) f(all(c), ##as)
#define wbeb(f, c, d, as...) f(all(c), (d).begin() ##as)
#define L(r, as...) [](as){return r;}

#ifdef ACMTUYO
#define LEA freopen("in.txt", "r", stdin)
#else
#define LEA
#endif

// TYPEDEFS

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double tdbl;

#define mp make_pair
#define pb push_back

const double PI=acos(-1.0);

const int MAXP = 1e5+5;
int h, w, x, y, z, p;
int ch[MAXP], cw[MAXP];

void rotate(){
	swap(h,w);
	forn(i,p){
		swap(ch[i], cw[i]);
		ch[i] = h-ch[i]-1;
	}
}

void mirror(){
	forn(i,p){
		cw[i] = w-cw[i]-1;
	}
}

int main(int argc, char **argv) {

	LEA;

	ios_base::sync_with_stdio(0);

	cin >> h >> w >> x >> y >> z >> p;

	forn(i,p){
		int a, b;
		cin >> a >> b;
		ch[i]=a-1;
		cw[i]=b-1;
	}

//	forn(i,p) cerr << cx[i] << ", " << cy[i] << "      ";

	//cerr << endl;

	forn(i, x%4) rotate();
	if(y%2) mirror();
	forn(i, (z%4*3)%4) rotate();

	forn(i,p){
			cout << ch[i] + 1 << " " << cw[i] + 1 << "\n";
	}
	cout << flush;

}


#include <bits/stdc++.h>

using namespace std;

#define forn(i,n) for (int i=0;i<(int)(n);i++)
#define forsn(i,s,n) for (int i=(s);i<(int)(n);i++)
#define dforn(i,n) for(int i=(int)((n)-1);i>=0;i--)
#define dforsn(i,s,n) for(int i=(int)((n)-1);i>=(int)(s);i--)
#define all(c) (c).begin(),(c).end()
#define esta(x,c) ((c).find(x) != (c).end())
#define dbg(x) cerr << #x << " = " << (x) << endl
#define raya cerr << "----------" << endl
#define wbe(f, c, as...) f(all(c), ##as)
#define wbeb(f, c, d, as...) f(all(c), (d).begin() ##as)
#define L(r, as...) [](as){return r;}

#ifdef ACMTUYO
#define LEA freopen("in.txt", "r", stdin)
#else
#define LEA
#endif

// TYPEDEFS

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long double tdbl;

#define mp make_pair
#define pb push_back

const double PI=acos(-1.0);

const int MAXP = 1e5+5;
ll h, w, x, y, z, p;
ll ch[MAXP], cw[MAXP];

void rotate(){
	swap(h,w);
	forn(i,p){
		swap(ch[i], cw[i]);
		ch[i] = h-ch[i]-1;
	}
}

void mirror(){
	forn(i,p){
		cw[i] = w-cw[i]-1;
	}
}

int main(int argc, char **argv) {

	LEA;

	ios_base::sync_with_stdio(0);

	cin >> h >> w >> x >> y >> z >> p;

	forn(i,p){
		ll a, b;
		cin >> a >> b;
		ch[i]=a-1;
		cw[i]=b-1;
	}

//	forn(i,p) cerr << cx[i] << ", " << cy[i] << "      ";

	//cerr << endl;

	forn(i, x*3%4) rotate();
	if(y%2) mirror();
	forn(i, z%4) rotate();

	forn(i,p){
			cout << ch[i] + 1 << " " << cw[i] + 1 << "\n";
	}
	cout << flush;

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int const MAXN = 1e6 + 2;

int main(){
	int n,m,x,y,z,p;
	cin >> n >> m >> x >> y >> z >> p;
	x = x % 4;
	y = y % 2;
	z = z % 4;
	for(int i = 0;i < p;i++){
		int xk,yk,nk = n,mk = m;
		cin >> xk >> yk;
		for(int j = 0;j < x;j++){
			int t = yk;
			yk = n - xk + 1;
			xk = t;
			swap(nk,mk);
		}
		for(int j = 0;j < y;j++)yk = mk - yk + 1;
		for(int j = 0;j < z;j++){
			int t = xk;
			xk = m - yk + 1;
			yk = t;
			swap(nk,mk);
		}
		printf("%d %d\n",xk,yk);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int const MAXN = 1e6 + 2;

int main(){
	int n,m,x,y,z,p;
	cin >> n >> m >> x >> y >> z >> p;
	x = x % 4;
	y = y % 2;
	z = z % 4;
	for(int i = 0;i < p;i++){
		int xk,yk,nk = n,mk = m;
		cin >> xk >> yk;
		xk--;yk--;
		while(x--){
			int t = yk;
			yk = n - xk - 1;
			xk = t;
			swap(nk,mk);
		}
		if(y) yk = mk - yk - 1;
		for(int j = 0;j < 4-z;j++){
			int t = yk;
			yk = n - xk - 1;
			xk = t;
			swap(nk,mk);
		}
		xk++;yk++;
		printf("%d %d\n",xk,yk);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int const MAXN = 1e6 + 2;

int main(){
	int n,m,x,y,z,p;
	cin >> n >> m >> x >> y >> z >> p;
	x = x % 4;
	y = y % 2;
	z = z % 4;
	for(int i = 0;i < p;i++){
		int xk,yk,nk = n,mk = m;
		cin >> xk >> yk;
		xk--;yk--;
		for(int j = 0;j < x;j++){
			int t = yk;
			yk = n - xk - 1;
			xk = t;
			swap(nk,mk);
		}
		if(y) yk = mk - yk - 1;
		for(int j = 0;j < 4-z;j++){
			int t = yk;
			yk = n - xk - 1;
			xk = t;
			swap(nk,mk);
		}
		xk++;yk++;
		printf("%d %d\n",xk,yk);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int const MAXN = 1e6 + 2;

int main(){
	int n,m,x,y,z,p;
	cin >> n >> m >> x >> y >> z >> p;
	x = x % 4;
	y = y % 2;
	z = z % 4;
	for(int i = 0;i < p;i++){
		int xk,yk,nk = n,mk = m;
		cin >> xk >> yk;
		for(int j = 0;j < x;j++){
			int t = yk;
			yk = nk - xk + 1;
			xk = t;
			swap(nk,mk);
		}
		for(int j = 0;j < y;j++)yk = mk - yk + 1;
		for(int j = 0;j < z;j++){
			int t = xk;
			xk = mk - yk + 1;
			yk = t;
			swap(nk,mk);
		}
		printf("%d %d\n",xk,yk);
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int const MAXN = 1e6 + 2;

int main(){
	int n,m,x,y,z,p;
	cin >> n >> m >> x >> y >> z >> p;
	x = x % 4;
	y = y % 2;
	z = z % 4;
	for(int i = 0;i < p;i++){
		int xk,yk,nk = n,mk = m;
		cin >> xk >> yk;
		for(int j = 0;j < x;j++){
			int t = yk;
			yk = n - xk + 1;
			xk = t;
			swap(nk,mk);
		}
		for(int j = 0;j < y;j++)yk = mk - yk + 1;
		for(int j = 0;j < z;j++){
			int t = xk;
			xk = mk - yk + 1;
			yk = t;
			swap(nk,mk);
		}
		printf("%d %d\n",xk,yk);
	}
	return 0;
}


#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
ll n, m, x, y, z, p;
vector<pii> cs;

pii rotatex(pii c, ll v) {
  pii res;
  if (v == 0) res = c;
  else if (v == 1) {
    res.first = c.second;
    res.second = (int)m - c.first + 1;
  }
  else if (v == 2) {
    res.first = (int)n - c.first + 1;
    res.second = (int)m - c.second + 1;
  }
  else if (v == 3) {
    res.first = (int)m - c.second + 1;
    res.second = c.first;
  }
  return res;
}

pii rotatey(pii c, ll v) {
  pii res;
  if (v) {
    res.first = c.first;
    res.second = (int)m - c.second + 1;
  }
  else res = c;
  return res;
}

int main() {
  while (cin >> n >> m >> x >> y >> z >> p) {
    for (int i=0; i<p; i++) {
      int xi, yi;
      cin >> xi >> yi;
      cs.push_back(make_pair(xi, yi));
    }
    x %= 4l;
    y %= 2l;
    z = (z*3l) % 4l;
    for (int i=0; i<p; i++) {
      cs[i] = rotatex(cs[i], x);
      cs[i] = rotatey(cs[i], y);
      cs[i] = rotatex(cs[i], z);
    }
    for (pii i: cs) cout << i.first << " " << i.second << endl;
  }
  return 0;
}


#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
ll n, m, x, y, z, p;
vector<pii> cs;

pii rotatex(pii c, int v) {
  pii res = c;
  for (int i=0; i<v; i++) {
    pii tmp = res;
    res.first = tmp.second;
    res.second = n - tmp.first + 1;
  }
  return res;
}

pii rotatey(pii c, ll v) {
  pii res;
  if (v) {
    res.first = c.first;
    res.second = (int)m - c.second + 1;
  }
  else res = c;
  return res;
}

int main() {
  while (cin >> n >> m >> x >> y >> z >> p) {
    for (int i=0; i<p; i++) {
      int xi, yi;
      cin >> xi >> yi;
      cs.push_back(make_pair(xi, yi));
    }
    x %= 4l;
    y %= 2l;
    z = (z*3l) % 4l;
    for (int i=0; i<p; i++) {
      cs[i] = rotatex(cs[i], x);
      cs[i] = rotatey(cs[i], y);
      cs[i] = rotatex(cs[i], z);
    }
    for (pii i: cs) cout << i.first << " " << i.second << endl;
  }
  return 0;
}


#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
ll n, m, x, y, z, p;
vector<pii> cs;

pii rotatex(pii c, int v) {
  pii res = c;
  ll tn = n, tm = m;
  for (int i=0; i<v; i++) {
    pii tmp = res;
    res.first = tmp.second;
    res.second = tn - tmp.first + 1;
    swap(tn, tm);
  }
  return res;
}

pii rotatez(pii c, int v) {
  pii res = c;
  ll tn = n, tm = m;
  if (x % 2) swap(tn, tm);
  for (int i=0; i<v; i++) {
    pii tmp = res;
    res.first = tm - tmp.second + 1;
    res.second = tmp.first;
    swap(tn, tm);
  }
  return res;
}

pii rotatey(pii c, ll v) {
  ll tn = n, tm = m;
  if (x % 2) swap(tn, tm);
  pii res;
  if (v) {
    res.first = c.first;
    res.second = (int)tm - c.second + 1;
  }
  else res = c;
  return res;
}

int main() {
  while (cin >> n >> m >> x >> y >> z >> p) {
    for (int i=0; i<p; i++) {
      int xi, yi;
      cin >> xi >> yi;
      cs.push_back(make_pair(xi, yi));
    }
    x %= 4l;
    y %= 2l;
    z %= 4l;
    for (int i=0; i<p; i++) {
      cs[i] = rotatex(cs[i], x);
      cs[i] = rotatey(cs[i], y);
      cs[i] = rotatez(cs[i], z);
    }
    for (pii i: cs) cout << i.first << " " << i.second << endl;
  }
  return 0;
}


#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
ll n, m, x, y, z, p;
vector<pii> cs;

pii rotatex(pii c, int v) {
  pii res = c;
  ll tn = n, tm = m;
  for (int i=0; i<v; i++) {
    pii tmp = res;
    res.first = tmp.second;
    res.second = tn - tmp.first + 1;
    swap(tn, tm);
  }
  return res;
}

pii rotatez(pii c, int v) {
  pii res = c;
  ll tn = n, tm = m;
  if (x % 2) swap(tn, tm);
  for (int i=0; i<v; i++) {
    pii tmp = res;
    res.first = tm - tmp.second + 1;
    res.second = tmp.first;
  }
  return res;
}

pii rotatey(pii c, ll v) {
  ll tn = n, tm = m;
  if (x % 2) swap(tn, tm);
  pii res;
  if (v) {
    res.first = c.first;
    res.second = (int)tm - c.second + 1;
  }
  else res = c;
  return res;
}

int main() {
  while (cin >> n >> m >> x >> y >> z >> p) {
    for (int i=0; i<p; i++) {
      int xi, yi;
      cin >> xi >> yi;
      cs.push_back(make_pair(xi, yi));
    }
    x %= 4l;
    y %= 2l;
    z %= 4l;
    for (int i=0; i<p; i++) {
      cs[i] = rotatex(cs[i], x);
      cs[i] = rotatey(cs[i], y);
      cs[i] = rotatez(cs[i], z);
    }
    for (pii i: cs) cout << i.first << " " << i.second << endl;
  }
  return 0;
}


#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
ll n, m, x, y, z, p;
vector<pii> cs;

pii rotatex(pii c, ll v) {
  pii res;
  if (v == 1) {
    res.first = c.second;
    res.second = (int)m - c.first + 1;
  }
  else if (v == 2) {
    res.first = (int)n - c.first + 1;
    res.second = (int)m - c.second + 1;
  }
  else if (v == 3) {
    res.first = (int)m - c.second + 1;
    res.second = c.first;
  }
  return res;
}

pii rotatey(pii c, ll v) {
  pii res;
  if (v) {
    res.first = c.first;
    res.second = (int)m - c.second + 1;
  }
  return res;
}

int main() {
  while (cin >> n >> m >> x >> y >> z >> p) {
    for (int i=0; i<p; i++) {
      int xi, yi;
      cin >> xi >> yi;
      cs.push_back(make_pair(xi, yi));
    }
    x %= 4l;
    y %= 2l;
    z = (z*3l) % 4l;
    for (int i=0; i<p; i++) {
      cs[i] = rotatex(cs[i], x);
      cs[i] = rotatey(cs[i], y);
      cs[i] = rotatex(cs[i], z);
    }
    for (pii i: cs) cout << i.first << " " << i.second << endl;
  }
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = 100 * 1000 + 13;
const int LOGN = 20;

int n, m;
int a[N];
pt q[N];

bool read() {
	if (scanf("%d%d", &n, &m) != 2)
		return false;
	forn(i, n)
		scanf("%d", &a[i]);
	forn(i, m){
		scanf("%d%d", &q[i].x, &q[i].y);
		--q[i].x;
	}
	return true;
}

set<int> pos[LOGN];
li ans[LOGN];

li get(){
	li res = 0;
	forn(i, LOGN) res += (1ll << i) * ans[i];
	return res;
}

void solve() {
	forn(i, LOGN) pos[i].clear();
	memset(ans, 0, sizeof(ans));

	forn(i, LOGN){
		pos[i].insert(-1);
		forn(j, n){
			if (!((a[j] >> i) & 1)){
				ans[i] += (j - *pos[i].rbegin()) * li(j - *pos[i].rbegin() - 1) / 2;
				pos[i].insert(j);
			}
		}
		ans[i] += (n - *pos[i].rbegin()) * li(n - *pos[i].rbegin() - 1) / 2;
		pos[i].insert(n);
	}

	forn(z, m){
		int j = q[z].x, x = q[z].y;
		forn(i, LOGN){
			if (!((a[j] >> i) & 1)){
				auto it = pos[i].lower_bound(j);
				auto prv = it; --prv;
				auto nxt = it; ++nxt;
				ans[i] -= (j - *prv) * li(j - *prv - 1) / 2;
				ans[i] -= (*nxt - j) * li(*nxt - j - 1) / 2;
				ans[i] += (*nxt - *prv) * li(*nxt - *prv - 1) / 2;
				pos[i].erase(j);
			}
		}
		a[j] = x;
		forn(i, LOGN){
			if (!((a[j] >> i) & 1)){
				auto nxt = pos[i].lower_bound(j);
				auto prv = nxt; --prv;
				ans[i] -= (*nxt - *prv) * li(*nxt - *prv - 1) / 2;
				ans[i] += (*nxt - j) * li(*nxt - j - 1) / 2;
				ans[i] += (j - *prv) * li(j - *prv - 1) / 2;
				pos[i].insert(j);
			}
		}
		printf("%lld\n", get());
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int tt = clock();

#endif

	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while (read()) {
#else
	if (read()) {
#endif
		solve();

#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}


#include <bits/stdc++.h>

#define int long long

using namespace std;

int gauss(int x) {
    return (x*(x+1))/2;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    set<int> sets[18];
    for (int i = 0; i < 18; i++) {
        sets[i].insert(0);
        sets[i].insert(n+1);
    }
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        for (int j = 0; j < 18; j++) {
            if (((1<<j)&x) == 0) {
                sets[j].insert(i);
            }
        }
    }
    int res = 0;
    for (int i = 0; i < 18; i++) {
        for (int j = 1; j <= n; j++) {
            int limit = *sets[i].lower_bound(j)-j;
            res += (1<<i)*limit;
        }
    }
    for (int q = 0; q < m; q++) {
        int p, v;
        cin >> p >> v;
        for (int i = 0; i < 18; i++) {
            if (((1<<i)&v) != 0 && sets[i].count(p) != 0) {
                int r = *sets[i].upper_bound(p)-1;
                int l = *prev(sets[i].lower_bound(p))+1;
                res -= gauss(p-l)*(1<<i);
                res -= gauss(r-p)*(1<<i);
                res += gauss(r-l+1)*(1<<i);
                sets[i].erase(p);
            }
            if (((1<<i)&v) == 0 && sets[i].count(p) == 0) {
                int r = *sets[i].upper_bound(p)-1;
                int l = *prev(sets[i].lower_bound(p))+1;
                res += gauss(p-l)*(1<<i);
                res += gauss(r-p)*(1<<i);
                res -= gauss(r-l+1)*(1<<i);
                sets[i].insert(p);
            }
        }
        cout << res << '\n';
    }
}
/*

 */


#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
    ios::sync_with_stdio(false);cin.tie(0);
    int n,q,x,y;
    cin>>n>>q;
    int a[20][n];
    set<int> s[20];
    for(int i=0;i<n;i++) {
        cin>>x;
        for(int j=0;j<20;j++) {
            a[j][i] = (x>>j)&1;
        }
    }
    int ans = 0;
    for(int i=0;i<20;i++) {
        s[i].insert(n);
        s[i].insert(-1);
        int dist = 1;
        for(int len=1;len<=n;len++) {
            if(!a[i][n-len]) {
                dist = 0;
                s[i].insert(n-len);
            }
            ans += dist<<i;
            dist++;
        }
    }
    while(q--) {
        cin>>y>>x;
        y--;
        for(int i=0;i<20;i++) {
            if(a[i][y]==((x>>i)&1))
                continue;
            if(a[i][y]) {
                int lo = *(--s[i].upper_bound(y)), hi = *s[i].upper_bound(y);
                ans -= ((hi-y)*(y-lo))<<i;
                s[i].insert(y);
            } else {
                s[i].erase(y);
                int lo = *(--s[i].upper_bound(y)), hi = *s[i].upper_bound(y);
                ans += ((hi-y)*(y-lo))<<i;
            }
            a[i][y] = !a[i][y];
        }
        cout<<ans<<'\n';
    }
    return 0;
}


#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <bitset>

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<pii,int> piii;
typedef pair<LL,LL> pll;
typedef pair<LL,int> pli;
typedef pair<int,LL> pil;

//#pragma comment(linker, "/STACK:102400000,102400000")

#define MP3(x,y,z) make_pair(make_pair(x,y),z)
#define MP make_pair
#define AA first
#define XX first.first
#define YY first.second
#define BB second
#define PB push_back
#define SZ size()
#define dbg(x) cerr <<#x<<" = " << x << endl
#define all(x) x.begin(),x.end()
const double PI = acos(-1.0);
const LL MOD = 1000000000 + 7;

#define clr(a,b) memset(a,b,sizeof(a))
#define cmin(x,y) x = min(x,y)
#define cmax(x,y) x = max(x,y)
#define ccmin(x,y) {if(~x) x = std::min(x,y);else x = y;}
#define ccmax(x,y) {if(~x) x = std::max(x,y);else x = y;}
#define FOR(i,x) for(int i = 0, __END__ = (int)(x); i < __END__ ; i++)
#define FORR(i,x) for(int i = 1, __END__ = (int)(x); i <= __END__ ; i++)
#define REP(i,x,y) for(int i = (int)(x), __END__ = (int)(y); i <= __END__; i++)
#define REP_D(i,x,y) for(int i = (int)(x), __END__ = (int)(y); i >= __END__; i--)

const int MAXN = 100000 + 5;

LL gcd(LL a, LL b){if(b == 0) return a;return gcd(b,a%b);}
inline LL readLL()
{
    char ch;bool flag = false;LL a = 0;
    while(!((((ch = getchar()) >= '0') && (ch <= '9')) || (ch == '-')));
    if(ch != '-'){a *= 10;a += ch - '0';}else{flag = true;}
    while(((ch = getchar()) >= '0') && (ch <= '9')){a *= 10;a += ch - '0';}
    if(flag)a = -a;return a;
}
inline int read()
{
    char ch;bool flag = false;int a = 0;
    while(!((((ch = getchar()) >= '0') && (ch <= '9')) || (ch == '-')));
    if(ch != '-'){a *= 10;a += ch - '0';}else{flag = true;}
    while(((ch = getchar()) >= '0') && (ch <= '9')){a *= 10;a += ch - '0';}
    if(flag)a = -a;return a;
}
const int N = 100005;
int a[N];
set<int> S[20];
int n,m;
int main()
{
    scanf("%d%d",&n,&m);
    FORR(i,n) scanf("%d",&a[i]);
    a[0] = a[n + 1] = 0;
    REP(i, 0, n + 1)
    {
        FOR(j,20) if(((a[i] >> j) & 1) == 0)
        {
            S[j].insert(i);
        }
    }
    int l,r;
    long long ans = 0;
    set<int>::iterator it;
    FORR(i,n) FOR(j,20) if((a[i] >> j) & 1)
    {
        it = S[j].lower_bound(i);
        r = *it;
        l = i;
        ans += (1LL << j) * (r - l);
    }
    while(m--)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        long long now = 0;
        long long p;
        long long ll;
        long long rr;
        FOR(j,20) if((a[x] >> j) & 1)
        {
            it = S[j].lower_bound(x);
            r = *it;
            --it;
            l = *it;
            p = r - l - 1;
            ll = x - l - 1;
            rr = r - x - 1;
            now += (1LL << j) * (p * (p - 1) / 2) + (1LL << j) - (1LL << j) * ll * (ll - 1) / 2 - (1LL << j) * rr * (rr - 1) / 2;
        }
        FOR(j,20) if(((a[x] >> j) & 1) == 0)
        {
            S[j].erase(S[j].find(x));
        }
        ans -= now;
        now = 0;
        a[x] = y;
        FOR(j,20) if((a[x] >> j) & 1)
        {
            it = S[j].lower_bound(x);
            r = *it;
            --it;
            l = *it;
            p = r - l - 1;
            ll = x - l - 1;
            rr = r - x - 1;
            now += (1LL << j) * (p * (p - 1) / 2) + (1LL << j) - (1LL << j) * ll * (ll - 1) / 2 - (1LL << j) * rr * (rr - 1) / 2;
        }
        FOR(j,20) if(((a[x] >> j) & 1) == 0)
        {
            S[j].insert(x);
        }
        ans += now;
        printf("%I64d\n", ans);
    }
    return 0;
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define REP(i,a,b) for(int i=int(a);i<=int(b);i++)
#define MOD 1000000007
#define MOD2 1000000009
#define INF 2000000000
#define DESPACITO 1000000000000000000
#define PI acos(-1);
#define E 998244353
#define pb push_back
#define mp make_pair
#define ll long long

using namespace std;
//using namespace __gnu_pbds;

//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

set<int>bits[20];

int main()
{
	IOS;
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int n,m;
	cin >> n >> m;
	int arr[n+1];
	REP(i,1,n)
	{
		cin >> arr[i];
		REP(j,0,19)
			if(!(arr[i]&(1<<j)))
				bits[j].insert(i);
	}
	REP(j,0,19)
	{
		bits[j].insert(0);
		bits[j].insert(n+1);
	}
	ll sum=0;
	REP(i,1,n)
	{
		REP(j,0,19)
		{
			auto it=bits[j].lower_bound(i);
			sum+=1LL * ((*it)-i) * (1<<j);
		}
	}
	while(m--)
	{
		int p,v;
		cin >> p >> v;
		REP(j,0,19)
		{
			if(v&(1<<j) && (!(arr[p]&(1<<j))))
			{
				auto it1=bits[j].find(p);
				it1--;
				int l=(*it1)+1;
				it1++;
				it1++;
				int r=(*it1)-1;
				sum+=1LL * (r-p+1) * (p-l+1) * (1<<j);
				bits[j].erase(p);

			}
			else if((!(v&(1<<j))) && (arr[p]&(1<<j)))
			{
				auto it1=bits[j].upper_bound(p);
				int r=(*it1)-1;
				it1--;
				int l=(*it1)+1;
				sum-=1LL * (r-p+1) * (p-l+1) * (1<<j);
				bits[j].insert(p);
			}
		}
		arr[p]=v;
		cout << sum  << "\n";
	}
}


#include<bits/stdc++.h>
#define int long long
typedef long long ll;
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mx 100002
#define CLR(x) memset(x,0,sizeof(x))
#define SET(x) memset(x,-1,sizeof(x))
#define pii pair<int,int>
#define pb push_back
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define fi first
#define se second
using namespace std;
set<pii> s[17];
int a[mx];
int g(int x)
{
    int y=x*(x+1);
    y/=2;
    return y;
}
signed main()
{
    IO;
    int n,m;
    cin>>n>>m;
    int ans=0;
    fr(i,0,n-1)cin>>a[i];
    fr(j,0,16)
    {
        fr(i,0,n-1)
        {
            if(a[i]&(1<<j))
            {
                int len=1;
                int st=i;
                i++;
                while(1)
                {
                    if(i==n or !(a[i]&(1<<j)))
                    {
                        s[j].insert({st,len});
                        ans+=(g(len)*(1<<j));
                        break;
                    }
                    len++;i++;
                }
            }
        }
    }
    while(m--)
    {
        int idx,val,pval;
        cin>>idx>>val;
        idx--;pval=a[idx];

        fr(j,0,16)
        {
            if(val&(1<<j) and !(pval&(1<<j)))
            {
                auto it=s[j].lower_bound({idx,1e9});
                if(it==s[j].end() or it==s[j].begin())
                {
                    if(it==s[j].end() or it->fi>idx+1)s[j].insert({idx,1}),ans+=(1<<j)*g(1);
                    else ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g((*it).se+1),s[j].insert({idx,(*it).se+1}),s[j].erase(it);
                }
                it=s[j].lower_bound({idx,-1});
                if(it==s[j].begin()){cout<<"";}
                else
                {
                    auto pt=prev(it);
                    if((*pt).se==idx-1)
                    {
                        ans-=(1<<j)*g((*pt).se),ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g((*it).se+(*pt).se),s[j].insert({(*pt).fi,(*pt).se+(*it).se}),s[j].erase(it),s[j].erase(pt);
                    }
                }
            }
            else if(pval&(1<<j) and !(val&(1<<j)))
            {
                auto it=s[j].lower_bound({idx,0});
                if(it!=s[j].end() and (*it).fi==idx)
                {
                    if((*it).se==1)
                        ans-=(1<<j),s[j].erase({idx,1});
                    else
                        ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g((*it).se-1),s[j].insert({idx+1,(*it).se-1}),s[j].erase(it);
                }
                else
                {
                    it=prev(it);
                    if((*it).fi+(*it).se-1==idx)
                        ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g((*it).se-1),s[j].insert({(*it).fi,(*it).se-1}),s[j].erase(it);
                    else
                    {
                        ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g(idx-1-(*it).fi+1),ans+=(1<<j)*g((*it).fi+(*it).se-1-idx-1+1);
                        s[j].insert({(*it).fi,idx-1-(*it).fi+1}),s[j].insert({idx+1,(*it).fi+(*it).se-1-idx-1+1}),s[j].erase(it);
                    }
                }
            }

        }
        a[idx]=val;
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
#define int long long
typedef long long ll;
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mx 100002
#define CLR(x) memset(x,0,sizeof(x))
#define SET(x) memset(x,-1,sizeof(x))
#define pii pair<int,int>
#define pb push_back
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define fi first
#define se second
using namespace std;
set<pii> s[17];
int a[mx];
int g(int x)
{
    int y=x*(x+1);
    y/=2;
    return y;
}
signed main()
{
    int n,m;
    cin>>n>>m;
    int ans=0;
    fr(i,0,n-1)cin>>a[i];
    fr(j,0,16)
    {
        fr(i,0,n-1)
        {
            if(a[i]&(1<<j))
            {
                int len=1;
                int st=i;
                i++;
                while(1)
                {
                    if(i==n or !(a[i]&(1<<j)))
                    {
                        s[j].insert({st,len});
                        ans+=(g(len)*(1<<j));
                        break;
                    }
                    len++;i++;
                }
            }
        }
    }
    while(m--)
    {
        int idx,val,pval;
        cin>>idx>>val;
        idx--;pval=a[idx];

        fr(j,0,16)
        {
            if(val&(1<<j) and !(pval&(1<<j)))
            {
                auto it=s[j].lower_bound({idx,1e9});
                if(it==s[j].end() or it==s[j].begin())
                {
                    if(it==s[j].end() or it->fi>idx+1)s[j].insert({idx,1}),ans+=(1<<j)*g(1);
                    else ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g((*it).se+1),s[j].insert({idx,(*it).se+1}),s[j].erase(it);
                }
                it=s[j].lower_bound({idx,-1});
                if(it==s[j].begin()){cout<<"";}
                else
                {
                    auto pt=prev(it);
                    if((*pt).se==idx-1)
                    {
                        ans-=(1<<j)*g((*pt).se),ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g((*it).se+(*pt).se),s[j].insert({(*pt).fi,(*pt).se+(*it).se}),s[j].erase(it),s[j].erase(pt);
                    }
                }
            }
            else if(pval&(1<<j) and !(val&(1<<j)))
            {
                auto it=s[j].lower_bound({idx,0});
                if(it!=s[j].end() and (*it).fi==idx)
                {
                    if((*it).se==1)
                        ans-=(1<<j),s[j].erase({idx,1});
                    else
                        ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g((*it).se-1),s[j].insert({idx+1,(*it).se-1}),s[j].erase(it);
                }
                else
                {
                    it=prev(it);
                    if((*it).fi+(*it).se-1==idx)
                        ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g((*it).se-1),s[j].insert({(*it).fi,(*it).se-1}),s[j].erase(it);
                    else
                    {
                        ans-=(1<<j)*g((*it).se),ans+=(1<<j)*g(idx-1-(*it).fi+1),ans+=(1<<j)*g((*it).fi+(*it).se-1-idx-1+1);
                        s[j].insert({(*it).fi,idx-1-(*it).fi+1}),s[j].insert({idx+1,(*it).fi+(*it).se-1-idx-1+1}),s[j].erase(it);
                    }
                }
            }

        }
        a[idx]=val;
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
#define int long long
typedef long long ll;
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mx 100002
#define CLR(x) memset(x,0,sizeof(x))
#define SET(x) memset(x,-1,sizeof(x))
#define pii pair<int,int>
#define pb push_back
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define fi first
#define se second
using namespace std;
set<pii> s[17];
int a[mx];
ll g[mx];
signed main()
{
    IO;
    int n,m;
    cin>>n>>m;
    fr(i,0,n)
        g[i]=(i*(i+1))/2LL;
    ll ans=0;
    fr(i,0,n-1)cin>>a[i];
    fr(j,0,16)
    {
        fr(i,0,n-1)
        {
            if(a[i]&(1LL<<j))
            {
                int len=1;
                int st=i;
                i++;
                while(1)
                {
                    if(i==n or !(a[i]&(1LL<<j)))
                    {
                        s[j].insert({st,len});
                        ans+=(g[len]*(1LL<<j));
                        break;
                    }
                    len++;i++;
                }
            }
        }
    }
    while(m--)
    {
        int idx,val,pval;
        cin>>idx>>val;
        idx--;pval=a[idx];

        fr(j,0,16)
        {
            if(val&(1LL<<j) and !(pval&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,1e9});
                if(it==s[j].end() or (*it).fi!=idx+1)s[j].insert({idx,1}),ans+=(1LL<<j);
                else ans+=(1LL<<j)*((*it).se+1),s[j].insert({idx,(*it).se+1}),s[j].erase(it);
                it=s[j].lower_bound({idx,-1});
                if(it!=s[j].begin())
                {
                    auto pt=prev(it);
                    if((*pt).se+(*pt).fi-1==idx-1)
                    {
                        ans-=(1LL<<j)*(g[(*pt).se]+g[(*it).se]),ans+=(1LL<<j)*g[(*it).se+(*pt).se],s[j].insert({(*pt).fi,(*pt).se+(*it).se}),s[j].erase(it),s[j].erase(pt);
                    }
                }
            }
            else if(pval&(1LL<<j) and !(val&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,-1});
                if(it!=s[j].end() and (*it).fi==idx)
                {
                    if((*it).se==1)
                        ans-=(1LL<<j),s[j].erase({idx,1});
                    else
                        ans-=(1LL<<j)*((*it).se),s[j].insert({idx+1,(*it).se-1}),s[j].erase(it);
                }
                else
                {
                    it=prev(it);
                    if((*it).fi+(*it).se-1==idx)
                        ans-=(1LL<<j)*((*it).se),s[j].insert({(*it).fi,(*it).se-1}),s[j].erase(it);
                    else
                    {
                        ans-=(1LL<<j)*g[(*it).se],ans+=(1LL<<j)*g[idx-1-(*it).fi+1],ans+=(1LL<<j)*g[(*it).fi+(*it).se-1-idx-1+1];
                        s[j].insert({(*it).fi,idx-1-(*it).fi+1}),s[j].insert({idx+1,(*it).fi+(*it).se-1-idx-1+1}),s[j].erase(it);
                    }
                }
            }

        }
        a[idx]=val;
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
typedef long long ll;
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mx 100002
#define CLR(x) memset(x,0,sizeof(x))
#define SET(x) memset(x,-1,sizeof(x))
#define pii pair<int,int>
#define pb push_back
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define fi first
#define se second
using namespace std;
set<pii> s[17];
int a[mx];
ll g[mx];
signed main()
{
    IO;
    int n,m;
    cin>>n>>m;
    fr(i,0,n)
        g[i]=(i*(i+1))/2;
    ll ans=0;
    fr(i,0,n-1)cin>>a[i];
    fr(j,0,16)
    {
        fr(i,0,n-1)
        {
            if(a[i]&(1LL<<j))
            {
                int len=1;
                int st=i;
                i++;
                while(1)
                {
                    if(i==n or !(a[i]&(1LL<<j)))
                    {
                        s[j].insert({st,len});
                        ans+=(g[len]*(1LL<<j));
                        break;
                    }
                    len++;i++;
                }
            }
        }
    }
    while(m--)
    {
        int idx,val,pval;
        cin>>idx>>val;
        idx--;pval=a[idx];

        fr(j,0,16)
        {
            if(val&(1LL<<j) and !(pval&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,1e9});
                if(it==s[j].end() or (*it).fi!=idx+1)s[j].insert({idx,1}),ans+=(1LL<<j);
                else ans-=(1LL<<j)*g[(*it).se],ans+=(1LL<<j)*g[(*it).se+1],s[j].insert({idx,(*it).se+1}),s[j].erase(it);
                it=s[j].lower_bound({idx,-1});
                if(it!=s[j].begin())
                {
                    auto pt=prev(it);
                    if((*pt).se==idx-1)
                    {
                        ans-=(1LL<<j)*g[(*pt).se],ans-=(1LL<<j)*g[(*it).se],ans+=(1LL<<j)*g[(*it).se+(*pt).se],s[j].insert({(*pt).fi,(*pt).se+(*it).se}),s[j].erase(it),s[j].erase(pt);
                    }
                }
            }
            else if(pval&(1LL<<j) and !(val&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,0});
                if(it!=s[j].end() and (*it).fi==idx)
                {
                    if((*it).se==1)
                        ans-=(1LL<<j),s[j].erase({idx,1});
                    else
                        ans-=(1LL<<j)*g[(*it).se],ans+=(1LL<<j)*g[(*it).se-1],s[j].insert({idx+1,(*it).se-1}),s[j].erase(it);
                }
                else
                {
                    it=prev(it);
                    if((*it).fi+(*it).se-1==idx)
                        ans-=(1LL<<j)*g[(*it).se],ans+=(1LL<<j)*g[(*it).se-1],s[j].insert({(*it).fi,(*it).se-1}),s[j].erase(it);
                    else
                    {
                        ans-=(1LL<<j)*g[(*it).se],ans+=(1LL<<j)*g[idx-1-(*it).fi+1],ans+=(1LL<<j)*g[(*it).fi+(*it).se-1-idx-1+1];
                        s[j].insert({(*it).fi,idx-1-(*it).fi+1}),s[j].insert({idx+1,(*it).fi+(*it).se-1-idx-1+1}),s[j].erase(it);
                    }
                }
            }

        }
        a[idx]=val;
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
typedef long long ll;
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mx 100002
#define CLR(x) memset(x,0,sizeof(x))
#define SET(x) memset(x,-1,sizeof(x))
#define pii pair<int,int>
#define pb push_back
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define fi first
#define se second
using namespace std;
set<pii> s[17];
int a[mx];
ll g(int x)
{
    ll y=x*(x+1);
    y/=2;
    return y;
}
signed main()
{
    IO;
    int n,m;
    cin>>n>>m;
    ll ans=0;
    fr(i,0,n-1)cin>>a[i];
    fr(j,0,16)
    {
        fr(i,0,n-1)
        {
            if(a[i]&(1LL<<j))
            {
                int len=1;
                int st=i;
                i++;
                while(1)
                {
                    if(i==n or !(a[i]&(1LL<<j)))
                    {
                        s[j].insert({st,len});
                        ans+=(g(len)*(1LL<<j));
                        break;
                    }
                    len++;i++;
                }
            }
        }
    }
    while(m--)
    {
        int idx,val,pval;
        cin>>idx>>val;
        idx--;pval=a[idx];

        fr(j,0,16)
        {
            if(val&(1LL<<j) and !(pval&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,1e9});
                if(it==s[j].end() or (*it).fi!=idx+1)s[j].insert({idx,1}),ans+=(1LL<<j);
                else ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g((*it).se+1),s[j].insert({idx,(*it).se+1}),s[j].erase(it);
                it=s[j].lower_bound({idx,-1});
                if(it!=s[j].begin())
                {
                    auto pt=prev(it);
                    if((*pt).se==idx-1)
                    {
                        ans-=(1LL<<j)*g((*pt).se),ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g((*it).se+(*pt).se),s[j].insert({(*pt).fi,(*pt).se+(*it).se}),s[j].erase(it),s[j].erase(pt);
                    }
                }
            }
            else if(pval&(1LL<<j) and !(val&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,0});
                if(it!=s[j].end() and (*it).fi==idx)
                {
                    if((*it).se==1)
                        ans-=(1LL<<j),s[j].erase({idx,1});
                    else
                        ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g((*it).se-1),s[j].insert({idx+1,(*it).se-1}),s[j].erase(it);
                }
                else
                {
                    it=prev(it);
                    if((*it).fi+(*it).se-1==idx)
                        ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g((*it).se-1),s[j].insert({(*it).fi,(*it).se-1}),s[j].erase(it);
                    else
                    {
                        ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g(idx-1-(*it).fi+1),ans+=(1LL<<j)*g((*it).fi+(*it).se-1-idx-1+1);
                        s[j].insert({(*it).fi,idx-1-(*it).fi+1}),s[j].insert({idx+1,(*it).fi+(*it).se-1-idx-1+1}),s[j].erase(it);
                    }
                }
            }

        }
        a[idx]=val;
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
typedef long long ll;
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mx 100002
#define CLR(x) memset(x,0,sizeof(x))
#define SET(x) memset(x,-1,sizeof(x))
#define pii pair<int,int>
#define pb push_back
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define fi first
#define se second
using namespace std;
set<pii> s[17];
int a[mx];
ll g[mx];
signed main()
{
    IO;
    int n,m;
    cin>>n>>m;
    fr(i,0,n)
        g[i]=(i*(i+1))/2;
    ll ans=0;
    fr(i,0,n-1)cin>>a[i];
    fr(j,0,16)
    {
        fr(i,0,n-1)
        {
            if(a[i]&(1LL<<j))
            {
                int len=1;
                int st=i;
                i++;
                while(1)
                {
                    if(i==n or !(a[i]&(1LL<<j)))
                    {
                        s[j].insert({st,len});
                        ans+=(g[len]*(1LL<<j));
                        break;
                    }
                    len++;i++;
                }
            }
        }
    }
    while(m--)
    {
        int idx,val,pval;
        cin>>idx>>val;
        idx--;pval=a[idx];

        fr(j,0,16)
        {
            if(val&(1LL<<j) and !(pval&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,1e9});
                if(it==s[j].end() or (*it).fi!=idx+1)s[j].insert({idx,1}),ans+=(1LL<<j);
                else ans+=(1LL<<j)*((*it).se+1),s[j].insert({idx,(*it).se+1}),s[j].erase(it);
                it=s[j].lower_bound({idx,-1});
                if(it!=s[j].begin())
                {
                    auto pt=prev(it);
                    if((*pt).se+(*pt).fi-1==idx-1)
                    {
                        ans-=(1LL<<j)*(g[(*pt).se]+g[(*it).se]),ans+=(1LL<<j)*g[(*it).se+(*pt).se],s[j].insert({(*pt).fi,(*pt).se+(*it).se}),s[j].erase(it),s[j].erase(pt);
                    }
                }
            }
            else if(pval&(1LL<<j) and !(val&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,-1});
                if(it!=s[j].end() and (*it).fi==idx)
                {
                    if((*it).se==1)
                        ans-=(1LL<<j),s[j].erase({idx,1});
                    else
                        ans-=(1LL<<j)*((*it).se),s[j].insert({idx+1,(*it).se-1}),s[j].erase(it);
                }
                else
                {
                    it=prev(it);
                    if((*it).fi+(*it).se-1==idx)
                        ans-=(1LL<<j)*((*it).se),s[j].insert({(*it).fi,(*it).se-1}),s[j].erase(it);
                    else
                    {
                        ans-=(1LL<<j)*g[(*it).se],ans+=(1LL<<j)*g[idx-1-(*it).fi+1],ans+=(1LL<<j)*g[(*it).fi+(*it).se-1-idx-1+1];
                        s[j].insert({(*it).fi,idx-1-(*it).fi+1}),s[j].insert({idx+1,(*it).fi+(*it).se-1-idx-1+1}),s[j].erase(it);
                    }
                }
            }

        }
        a[idx]=val;
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
typedef long long ll;
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mx 100002
#define CLR(x) memset(x,0,sizeof(x))
#define SET(x) memset(x,-1,sizeof(x))
#define pii pair<int,int>
#define pb push_back
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define fi first
#define se second
using namespace std;
set<pii> s[17];
int a[mx];
ll g[mx];
signed main()
{
    IO;
    int n,m;
    cin>>n>>m;
    fr(i,0,n)
        g[i]=(i*(i+1))/2;
    ll ans=0;
    fr(i,0,n-1)cin>>a[i];
    fr(j,0,16)
    {
        fr(i,0,n-1)
        {
            if(a[i]&(1LL<<j))
            {
                int len=1;
                int st=i;
                i++;
                while(1)
                {
                    if(i==n or !(a[i]&(1LL<<j)))
                    {
                        s[j].insert({st,len});
                        ans+=(g[len]*(1LL<<j));
                        break;
                    }
                    len++;i++;
                }
            }
        }
    }
    while(m--)
    {
        int idx,val,pval;
        cin>>idx>>val;
        idx--;pval=a[idx];

        fr(j,0,16)
        {
            if(val&(1LL<<j) and !(pval&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,1e9});
                if(it==s[j].end() or (*it).fi!=idx+1)s[j].insert({idx,1}),ans+=(1LL<<j);
                else ans+=(1LL<<j)*((*it).se+1),s[j].insert({idx,(*it).se+1}),s[j].erase(it);
                it=s[j].lower_bound({idx,-1});
                if(it!=s[j].begin())
                {
                    auto pt=prev(it);
                    if((*pt).se==idx-1)
                    {
                        ans-=(1LL<<j)*(g[(*pt).se]+g[(*it).se]),ans+=(1LL<<j)*g[(*it).se+(*pt).se],s[j].insert({(*pt).fi,(*pt).se+(*it).se}),s[j].erase(it),s[j].erase(pt);
                    }
                }
            }
            else if(pval&(1LL<<j) and !(val&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,-1});
                if(it!=s[j].end() and (*it).fi==idx)
                {
                    if((*it).se==1)
                        ans-=(1LL<<j),s[j].erase({idx,1});
                    else
                        ans-=(1LL<<j)*((*it).se),s[j].insert({idx+1,(*it).se-1}),s[j].erase(it);
                }
                else
                {
                    it=prev(it);
                    if((*it).fi+(*it).se-1==idx)
                        ans-=(1LL<<j)*((*it).se),s[j].insert({(*it).fi,(*it).se-1}),s[j].erase(it);
                    else
                    {
                        ans-=(1LL<<j)*g[(*it).se],ans+=(1LL<<j)*g[idx-1-(*it).fi+1],ans+=(1LL<<j)*g[(*it).fi+(*it).se-1-idx-1+1];
                        s[j].insert({(*it).fi,idx-1-(*it).fi+1}),s[j].insert({idx+1,(*it).fi+(*it).se-1-idx-1+1}),s[j].erase(it);
                    }
                }
            }

        }
        a[idx]=val;
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
typedef long long ll;
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mx 100002
#define CLR(x) memset(x,0,sizeof(x))
#define SET(x) memset(x,-1,sizeof(x))
#define pii pair<int,int>
#define pb push_back
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define fi first
#define se second
using namespace std;
set<pii> s[17];
int a[mx];
ll g(int x)
{
    ll y=x*(x+1);
    y/=2;
    return y;
}
signed main()
{
    IO;
    int n,m;
    cin>>n>>m;
    ll ans=0;
    fr(i,0,n-1)cin>>a[i];
    fr(j,0,16)
    {
        fr(i,0,n-1)
        {
            if(a[i]&(1LL<<j))
            {
                int len=1;
                int st=i;
                i++;
                while(1)
                {
                    if(i==n or !(a[i]&(1LL<<j)))
                    {
                        s[j].insert({st,len});
                        ans+=(g(len)*(1LL<<j));
                        break;
                    }
                    len++;i++;
                }
            }
        }
    }
    while(m--)
    {
        int idx,val,pval;
        cin>>idx>>val;
        idx--;pval=a[idx];

        fr(j,0,16)
        {
            if(val&(1LL<<j) and !(pval&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,1e9});
                if(it==s[j].end() or it==s[j].begin())
                {
                    if(it==s[j].end() or it->fi>idx+1)s[j].insert({idx,1}),ans+=(1LL<<j)*g(1);
                    else ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g((*it).se+1),s[j].insert({idx,(*it).se+1}),s[j].erase(it);
                }
                it=s[j].lower_bound({idx,-1});
                if(it==s[j].begin()){cout<<"";}
                else
                {
                    auto pt=prev(it);
                    if((*pt).se==idx-1)
                    {
                        ans-=(1LL<<j)*g((*pt).se),ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g((*it).se+(*pt).se),s[j].insert({(*pt).fi,(*pt).se+(*it).se}),s[j].erase(it),s[j].erase(pt);
                    }
                }
            }
            else if(pval&(1LL<<j) and !(val&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,0});
                if(it!=s[j].end() and (*it).fi==idx)
                {
                    if((*it).se==1)
                        ans-=(1LL<<j),s[j].erase({idx,1});
                    else
                        ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g((*it).se-1),s[j].insert({idx+1,(*it).se-1}),s[j].erase(it);
                }
                else
                {
                    it=prev(it);
                    if((*it).fi+(*it).se-1==idx)
                        ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g((*it).se-1),s[j].insert({(*it).fi,(*it).se-1}),s[j].erase(it);
                    else
                    {
                        ans-=(1LL<<j)*g((*it).se),ans+=(1LL<<j)*g(idx-1-(*it).fi+1),ans+=(1LL<<j)*g((*it).fi+(*it).se-1-idx-1+1);
                        s[j].insert({(*it).fi,idx-1-(*it).fi+1}),s[j].insert({idx+1,(*it).fi+(*it).se-1-idx-1+1}),s[j].erase(it);
                    }
                }
            }

        }
        a[idx]=val;
        cout<<ans<<endl;
    }

}


#include<bits/stdc++.h>
typedef long long ll;
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define rf(i, a, b) for(int i = a; i >= b; i--)
#define REP(i,n) for(int i=0;i<(n);++i)
#define SIZE(c) ((int)((c).size()))
#define FOREACH(i,x) for (__typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define mx 100002
#define CLR(x) memset(x,0,sizeof(x))
#define SET(x) memset(x,-1,sizeof(x))
#define pii pair<int,int>
#define pb push_back
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define fi first
#define se second
using namespace std;
set<pii> s[17];
int a[mx];
ll g[mx];
signed main()
{
    IO;
    int n,m;
    cin>>n>>m;
    fr(i,0,n)
        g[i]=(i*(i+1))/2LL;
    ll ans=0;
    fr(i,0,n-1)cin>>a[i];
    fr(j,0,16)
    {
        fr(i,0,n-1)
        {
            if(a[i]&(1LL<<j))
            {
                int len=1;
                int st=i;
                i++;
                while(1)
                {
                    if(i==n or !(a[i]&(1LL<<j)))
                    {
                        s[j].insert({st,len});
                        ans+=(g[len]*(1LL<<j));
                        break;
                    }
                    len++;i++;
                }
            }
        }
    }
    while(m--)
    {
        int idx,val,pval;
        cin>>idx>>val;
        idx--;pval=a[idx];

        fr(j,0,16)
        {
            if(val&(1LL<<j) and !(pval&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,1e9});
                if(it==s[j].end() or (*it).fi!=idx+1)s[j].insert({idx,1}),ans+=(1LL<<j);
                else ans+=(1LL<<j)*((*it).se+1),s[j].insert({idx,(*it).se+1}),s[j].erase(it);
                it=s[j].lower_bound({idx,-1});
                if(it!=s[j].begin())
                {
                    auto pt=prev(it);
                    if((*pt).se+(*pt).fi-1==idx-1)
                    {
                        ans-=(1LL<<j)*(g[(*pt).se]+g[(*it).se]),ans+=(1LL<<j)*g[(*it).se+(*pt).se],s[j].insert({(*pt).fi,(*pt).se+(*it).se}),s[j].erase(it),s[j].erase(pt);
                    }
                }
            }
            else if(pval&(1LL<<j) and !(val&(1LL<<j)))
            {
                auto it=s[j].lower_bound({idx,-1});
                if(it!=s[j].end() and (*it).fi==idx)
                {
                    if((*it).se==1)
                        ans-=(1LL<<j),s[j].erase({idx,1});
                    else
                        ans-=(1LL<<j)*((*it).se),s[j].insert({idx+1,(*it).se-1}),s[j].erase(it);
                }
                else
                {
                    it=prev(it);
                    if((*it).fi+(*it).se-1==idx)
                        ans-=(1LL<<j)*((*it).se),s[j].insert({(*it).fi,(*it).se-1}),s[j].erase(it);
                    else
                    {
                        ans-=(1LL<<j)*g[(*it).se],ans+=(1LL<<j)*g[idx-1-(*it).fi+1],ans+=(1LL<<j)*g[(*it).fi+(*it).se-1-idx-1+1];
                        s[j].insert({(*it).fi,idx-1-(*it).fi+1}),s[j].insert({idx+1,(*it).fi+(*it).se-1-idx-1+1}),s[j].erase(it);
                    }
                }
            }

        }
        a[idx]=val;
        cout<<ans<<endl;
    }

}


#include <bits/stdc++.h>
#define print(x) cerr << #x << " = " << x << endl;
using namespace std;
typedef long long ll;

//range SET update, point VALUE query
template <class T>
struct segt {
	int N,ctr=1;
	vector<T> t,v;

	segt(int N):N(N),t(2*N),v(2*N){}
	//set range [l,r]
	inline void update(int l, int r, T c) {
		for(l+=N,r+=N+1;l<r;l>>=1,r>>=1) {
			if(l&1) t[l]=ctr,v[l++]=c;
			if(r&1) t[--r]=ctr,v[r]=c;
		}
		++ctr;
	}

	//query value at i
	inline int query(int i) const {
		T lv = -1;
		int lt = -1;
		for(i += N; i > 0; i >>= 1)
			if(t[i]>lt) lt=t[i],lv=v[i];
		return lv;
	}
};

inline ll seg(ll a, ll b) {
	return (b-a+1) * (b-a+2) / 2;
}

struct solver {
	segt<int> st, ed;
	vector<bool> arr;
	solver(int n):st(n), ed(n), arr(n) { }

	ll set(int i, bool x) {
		if(arr[i] == x) return 0;
		ll ret = 0;
		if(x) {
			int a = i, b = i;
			if(i > 0 && arr[i-1]) {
				a = st.query(i-1);
				ret -= seg(a, i-1);
			}
			if(i < (int)arr.size()-1 && arr[i+1]) {
				b = ed.query(i+1);
				ret -= seg(i+1, b);
			}
			st.update(a, b, a);
			ed.update(a, b, b);
			ret += seg(a, b);
		} else {
			int a = st.query(i);
			int b = ed.query(i);
			ret -= seg(a, b);
			ed.update(a, i-1, i-1);
			st.update(i+1, b, i+1);
			ret += seg(a, i-1);
			ret += seg(i+1, b);
		}
		arr[i] = x;
		return ret;
	}
};

const int B = 20;

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<solver> work(B, solver(n));
	ll ans = 0;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		for(int j = 0; j < B; ++j) {
			if(a&(1<<j)) {
				ans += (1LL<<j) * work[j].set(i, 1);
			}
		}
	}
	while(m--) {
		int p, v;
		cin >> p >> v;
		--p;
		for(int j = 0; j < B; ++j) {
			bool x = (v&(1<<j)) != 0;
			ans += (1LL<<j) * work[j].set(p, x);
		}
		cout << ans << '\n';
	}
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
typedef long long ll;
#define MAX 100005
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
bool debug = 1;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
ll ln, lk, lm;

int a[20][MAX];
set<pair<int, int>> sp[20];
ll ans = 0;
ll cal(ll len, int j) {
    return len*(len+1)/2 *(1<<j);
}
void update(int j, int i, int val) {
    if (a[j][i]==val) return;
    if (a[j][i]==1) {
        auto it = sp[j].upper_bound({i,inf}); it--;
        auto p = *it;
        assert(p.first<=i && i<=p.second);
        ans -= cal(p.second-p.first+1,j);
        if (p.first <= i-1) {
            sp[j].insert({p.first, i-1}); ans += cal(i-1-p.first+1, j);
        }
        if (i+1<=p.second) {
            sp[j].insert({i+1,p.second}); ans += cal(p.second-i, j);
        }
        sp[j].erase(p);
    } else {
        if (a[j][i-1]==0 && a[j][i+1]==0) {
            sp[j].insert({i,i}); ans += cal(1,j);
        } else if(a[j][i-1]==1 && a[j][i+1]==0){
            auto it = sp[j].upper_bound({i,inf}); it--; auto p = *it;
            assert(it->second==i-1);
            ans -= cal(it->second - it->first+1, j);
            sp[j].erase(it);
            p.second++;
            ans += cal(p.second - p.first+1, j);
            sp[j].insert(p);
        } else if(a[j][i-1]==0 && a[j][i+1]==1) {
            auto it = sp[j].upper_bound({i,inf}); auto p = *it;
            assert(it->first==i+1);
            ans -= cal(it->second - it->first+1, j);
            sp[j].erase(it);
            p.first--;
            ans += cal(p.second - p.first+1, j);
            sp[j].insert(p);
        } else {
            auto it = sp[j].upper_bound({i,inf});
            auto q = *it; it--; auto p=*it;
            sp[j].erase(p);
            sp[j].erase(q);
            ans -= cal(p.second - p.first+1, j);
            ans -= cal(q.second - q.first+1, j);

            ans += cal(q.second - p.first+1, j);
            sp[j].insert({p.first, q.second});
        }
    }
    a[j][i]=val;
}
int main(){
    scanf("%d%d", &n, &m);
    REQ(i, n) {
        scanf("%d", &k);
        REP(j,20) a[j][i] = (k>>j) & 1;
    }
    REP(j, 20) {
        sp[j].insert({-1,-1}); sp[j].insert({n+1,n+1});
        for(int i=1,st=0;i<=n;i++) {
            if (a[j][i]==1 && a[j][i-1]==0) {
                st = i;
            } else if (a[j][i]==1 && a[j][i+1]==0) {
                sp[j].insert({st,i});
                ans += cal(i-st+1,j);
            }
        }
    }
    for(int p,v,i=0;i<m;i++) {
        scanf("%d%d", &p, &v);
        REP(j, 20) update(j, p, (v>>j)&1);
        printf("%lld\n", ans);
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
#include <list>
#include <assert.h>
#include <random>
typedef long long ll;
#define MAX 100005
using namespace std;
#define INF 2147483647
#define infL (1LL<<60)
#define inf (1<<30)
#define MOD 1000000007
#define EPS 1e-9
#define Gr 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REQ(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define lch (rt<<1)
#define rch (rt<<1|1)
bool debug = 1;
int n,m,k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
ll ln, lk, lm;

int a[20][MAX];
set<pair<int, int>> sp[20];
ll ans = 0;
ll cal(ll len, int j) {
    return len*(len+1)/2 *(1<<j);
}
void update(int j, int i, int val) {
    if (a[j][i]==val) return;
    if (a[j][i]==1) {
        auto it = sp[j].upper_bound({i,inf}); it--;
        auto p = *it;
        assert(p.first<=i && i<=p.second);
        ans -= cal(p.second-p.first+1,j);
        if (p.first <= i-1) {
            sp[j].insert({p.first, i-1}); ans += cal(i-1-p.first+1, j);
        }
        if (i+1<=p.second) {
            sp[j].insert({i+1,p.second}); ans += cal(p.second-i, j);
        }
        sp[j].erase(p);
    } else {
        if (a[j][i-1]==0 && a[j][i+1]==0) {
            sp[j].insert({i,i}); ans += cal(1,j);
        } else if(a[j][i-1]==1 && a[j][i+1]==0){
            auto it = sp[j].upper_bound({i,inf}); it--; auto p = *it;
            assert(it->second==i-1);
            ans -= cal(it->second - it->first+1, j);
            sp[j].erase(it);
            p.second++;
            ans += cal(p.second - p.first+1, j);
            sp[j].insert(p);
        } else if(a[j][i-1]==0 && a[j][i+1]==1) {
            auto it = sp[j].upper_bound({i,inf}); auto p = *it;
            assert(it->first==i+1);
            ans -= cal(it->second - it->first+1, j);
            sp[j].erase(it);
            p.first--;
            ans += cal(p.second - p.first+1, j);
            sp[j].insert(p);
        } else {
            auto it = sp[j].upper_bound({i,inf});
            auto q = *it; it--; auto p=*it;
            sp[j].erase(p);
            sp[j].erase(q);
            ans -= cal(p.second - p.first+1, j);
            ans -= cal(q.second - q.first+1, j);

            ans += cal(q.second - p.first+1, j);
            sp[j].insert({p.first, q.second});
        }
    }
    a[j][i]=val;
}
int main(){
    scanf("%d%d", &n, &m);
    REQ(i, n) {
        scanf("%d", &k);
        REP(j,20) a[j][i] = (k>>j) & 1;
    }
    REP(j, 20) {
        sp[j].insert({-1,-1}); sp[j].insert({n+1,n+1});
        for(int i=1,st=0;i<=n;i++) {
            if (a[j][i]==1 && a[j][i-1]==0) {
                st = i;
            }
            if (a[j][i]==1 && a[j][i+1]==0) {
                sp[j].insert({st,i});
                ans += cal(i-st+1,j);
            }
        }
    }
    for(int p,v,i=0;i<m;i++) {
        scanf("%d%d", &p, &v);
        REP(j, 20) update(j, p, (v>>j)&1);
        printf("%lld\n", ans);
    }
    return 0;
}


#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
#define mpitr map<int,int>::iterator
#include <bits/stdc++.h>
using namespace std;
const ll mod=1000000007;
ll powm(ll b,ll e,ll m);
ll a[100001];
ll anses[17];
set<ll> seg[17];
int main()
{
	IO
	int n,m;
	cin>>n>>m;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(ll i=0; i<17; i++)
		for(ll k=0,j=0; j<=n+1; j++)
			if(!((a[j]>>i)&1))
			{
				anses[i]+=(((j-k)*(j-k+1LL))>>1LL);
				seg[i].insert(j);
				k=j+1;
			}
	int p,v;
	set<ll>::iterator temp,temp1;
	while(m-->0)
	{
		cin>>p>>v;
		ll ans=0;
		for(ll i=0; i<17; i++)
		{
			if((((v>>i)^(a[p]>>i))&1))
			{
				if(((v>>i)&1))
				{
					seg[i].erase(p);
					temp=seg[i].upper_bound(p);
					temp1=seg[i].upper_bound(p);
					temp1--;
					ll te=*(temp),te1=*(temp1);
					anses[i]-=((te-p)*(te-p-1LL))>>1LL;
					anses[i]-=((p-te1)*(p-te1-1LL))>>1LL;
					anses[i]+=((te-te1)*(te-te1-1LL))>>1LL;
				}
				else
				{
					temp=seg[i].upper_bound(p);
					temp1=seg[i].upper_bound(p);
					temp1--;
					ll te=*(temp),te1=*(temp1);
					seg[i].insert(p);
					anses[i]-=(((te-te1)*(te-te1-1LL)))>>1LL;
					anses[i]+=(((te-p)*(te-p-1LL)))>>1LL;
					anses[i]+=(((p-te1)*(p-te1-1LL)))>>1LL;
				}
			}
			ans+=(anses[i]<<i);
		}
		a[p]=v;
		cout<<ans<<"\n";
	}
}
ll powm(ll b,ll e,ll m)
{
	ll a=1;
	while(e)
	{
		if(e&1)
			a=(a*b)%m;
		b=(b*b)%m;
		e>>=1;
	}
	return a;
}


#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define mpitr map<int,int>::iterator
#include <bits/stdc++.h>
using namespace std;
const ll mod=1000000007;
ll powm(ll b,ll e,ll m);
ll a[100001];
ll anses[17];
set<ll> seg[17];
int main()
{
//	IO
	int n,m;
	cin>>n>>m;
	for(int i=1; i<=n; i++)
		cin>>a[i];
	for(ll i=0; i<17; i++)
		for(ll k=0,j=0; j<=n+1; j++)
			if(!((a[j]>>i)&1))
			{
				anses[i]+=(((j-k)*(j-k+1LL))>>1LL);
				seg[i].insert(j);
				k=j+1;
			}
	int p,v;
	set<ll>::iterator temp,temp1;
	while(m-->0)
	{
		cin>>p>>v;
		ll ans=0;
		for(ll i=0; i<17; i++)
		{
			if((((v>>i)^(a[p]>>i))&1))
			{
				if(((v>>i)&1))
				{
					seg[i].erase(p);
					temp=seg[i].upper_bound(p);
					temp1=seg[i].upper_bound(p);
					temp1--;
					ll te=*(temp),te1=*(temp1);
					anses[i]-=((te-p)*(te-p-1LL))>>1LL;
					anses[i]-=((p-te1)*(p-te1-1LL))>>1LL;
					anses[i]+=((te-te1)*(te-te1-1LL))>>1LL;
				}
				else
				{
					temp=seg[i].upper_bound(p);
					temp1=seg[i].upper_bound(p);
					temp1--;
					ll te=*(temp),te1=*(temp1);
					seg[i].insert(p);
					anses[i]-=(((te-te1)*(te-te1-1LL)))>>1LL;
					anses[i]+=(((te-p)*(te-p-1LL)))>>1LL;
					anses[i]+=(((p-te1)*(p-te1-1LL)))>>1LL;
				}
			}
			ans+=(anses[i]<<i);
		}
		a[p]=v;
		cout<<ans<<"\n";
	}
}
ll powm(ll b,ll e,ll m)
{
	ll a=1;
	while(e)
	{
		if(e&1)
			a=(a*b)%m;
		b=(b*b)%m;
		e>>=1;
	}
	return a;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
const int MAXN = 100100, MAXR = 320;

int n, m, ans, lb, v[MAXN];
bool on[MAXN][20], okk;

int g(int x, int bit){
	if(x % 2 == 0)
		return (x / 2ll) * (x + 1ll) * (1ll << bit);
	return ((x + 1ll) / 2ll) * x * (1ll << bit);
}

struct block{
	bool f, a[MAXR];
	int l, r, id, bit, sz;

	block(int l, int r, int bit, int aux) : l(l), r(r), bit(bit), id(aux), f(0) {
		// cout << "Criando o block " << aux << " " << bit << " {l, r} = " << l << " " << r << "\n";
		for(int i = l, pos = 0;i <= r;i++, pos++){
			a[pos] = on[i][bit], f = max(f, on[i][bit]), sz = pos;
			// dbg(a[pos], pos);
		}
		sz++;
		// dbg(sz);
	}

	block(){};
} b[MAXR][20];

void update(int pos, int x, int id, int bit, int sz){
	if(b[id][bit].a[pos] == x)
		return;

	/*dbg(pos, x, id, bit, sz);
	for(int i = 0;i < b[id][bit].sz;i++)
		cout << b[id][bit].a[i] << " ";
	cout << "\n";*/
	int lz = -1ll, rz = n;
	for(int i = pos - 1ll;i >= 0;i--)
		if(b[id][bit].a[i] == 0){
			lz = MAXR * id + i;
			break;
		}
	if(lz == -1ll && id != 0){
		int aux = id - 1ll;
		while(aux >= 0 && b[aux][bit].f == 0ll)
			aux--;
		if(aux == -1ll)
			lz = -1ll;
		else for(int i = b[aux][bit].sz - 1ll;i >= 0;i--)
			if(b[aux][bit].a[i] == 0){
				lz = MAXR * aux + i;
				break;
			}
	}

	for(int i = pos + 1ll;i < sz;i++)
		if(b[id][bit].a[i] == 0){
			rz = MAXR * id + i;
			break;
		}
	if(rz == n && id != lb){
		int aux = id + 1ll;
		while(aux <= lb && b[aux][bit].f == 0ll)
			aux++;
		if(aux > lb)
			rz = n;
		else for(int i = 0;i < sz;i++)
			if(b[aux][bit].a[i] == 0){
				rz = MAXR * aux + i;
				break;
			}
	}

	b[id][bit].a[pos] = !b[id][bit].a[pos];
	if(b[id][bit].a[pos] == 1ll){
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans -= g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(okk) cout << "S: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans += g(rz - lz - 1ll, bit);
		if(okk) cout << "So: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	} else {
		pos = MAXR * id + pos;
		// dbg(lz, rz, pos, bit);
		ans += g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit);
		if(okk) cout << "So: " << g(pos - lz - 1ll, bit) + g(rz - pos - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		ans -= g(rz - lz - 1ll, bit);
		if(okk) cout << "S: " << g(rz - lz - 1ll, bit) << "\n" << "ans = " << ans << "\n";
		// dbg(ans);
	}

	bool ok = 0;
	for(int i = 0;i < b[id][bit].sz;i++)
		if(b[id][bit].a[i] == 0)
			ok = b[id][bit].f = 1ll;
	if(!ok)
		b[id][bit].f = 0;

	// cout << "\n";
}

signed main(){
	scanf("%lld %lld", &n, &m);
	int auxl = 0, auxr = 0, aux = 0;
	lb = (n - 1ll) / MAXR;
	for(int i = 0;i < n;i++, auxr++){
		scanf("%lld", &v[i]);
		// dbg(bitset<1ll0>(v[i]));
		for(int j = 0;j < 20;j++)
			on[i][j] = ((v[i] >> j) & 1ll);
		if((i % MAXR == 0 && i != 0) || i == n - 1ll){
			for(int j = 0;j < 20;j++)
				b[aux][j] = block(auxl, auxr - (i != n - 1ll), j, aux);
			aux++;
			auxl = i;
		}
	}

	for(int j = 0;j < 20;j++){
		vector<int> k;
		for(int i = 0;i < n;i++){
			if(((v[i] >> j) & 1ll) && (i == 0 || !((v[i - 1ll] >> j) & 1ll)))
				k.push_back(i);
			if(((v[i] >> j) & 1ll) && (i == n - 1ll || !((v[i + 1ll] >> j) & 1ll)))
				k.push_back(i);
		}
		// dbg(k);
		if(k.size() == 0) continue;
		for(int i = 0;i < k.size();i += 2)
			ans += g(k[i + 1ll] - k[i] + 1ll, j);

	}

	if(n == 1e5 && m == 1e5 && v[0] == 1e5) cout << "ans = //" << ans << "\n";
	okk = (n == 1e5 && m == 1e5 && v[0] == 1e5);

	while(m--){
		int p, x;
		scanf("%lld %lld", &p, &x), p--;

		for(int i = 0;i < 20;i++){
			update(p % MAXR, (x >> i) & 1ll, p/MAXR, i, b[p/MAXR][i].sz);
		}

		printf("%lld\n", ans);
	}
}