stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>



const int MAX_N = int(1e5) + 10;



int n, m, ans_top;

std::vector<int> edges[MAX_N], tree[MAX_N];

std::pair<int, int> el[MAX_N], ans[MAX_N];

int par[MAX_N], deg[MAX_N];

bool in[MAX_N];



void dfs(int x, int p) {

	for (auto y : tree[x]) {

		if (y != p) {

			dfs(y, x);

		}

	}

	if (x == 1) return;

	if (deg[x] & 1) {

		ans[++ans_top] = std::make_pair(x, p);

		++deg[x];

	} else {

		ans[++ans_top] = std::make_pair(p, x);

		++deg[p];

	}

}



int find(int x) {

	return x == par[x] ? x : par[x] = find(par[x]);

}



void solve() {

	for (int i = 1; i <= n; ++i) {

		par[i] = i;

	}

	int tot = 0;

	for (int i = 1; i <= m; ++i) {

		int x = el[i].first, y = el[i].second;

		x = find(x);

		y = find(y);

		if (x != y) {

			in[i] = true;

			tree[el[i].first].push_back(el[i].second);

			tree[el[i].second].push_back(el[i].first);

			par[y] = x;

			++tot;

			if (tot == n - 1) break;

		}

	}

	ans_top = 0;

	for (int i = 1; i <= m; ++i) {

		if (!in[i]) {

			ans[++ans_top] = el[i];

			++deg[el[i].first];

		}

	}

	dfs(1, 0);

}



int main() {

	scanf("%d%d", &n, &m);

	if (m & 1) {

		puts("-1");

		return 0;

	}

	for (int i = 1; i <= m; ++i) {

		int x, y;

		scanf("%d%d", &x, &y);

		edges[x].push_back(y);

		edges[y].push_back(x);

		el[i] = std::make_pair(x, y);

	}



	solve();

	for (int i = 1; i <= m; ++i) {

		printf("%d %d\n", ans[i].first, ans[i].second);

	}

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;

struct E {

  int v;

  bool vis;

  E *next, *rev;

};



const int N = 100010;



int n, m;

bool vis[N], par[N];

E* g[N];



E* adde(int u, int v) {

  static E pool[N * 2], *p = pool;

  ++p;

  p->v = v;

  p->next = g[u];

  g[u] = p;

  return p;

}



void dfs(int u) {

  vis[u] = true;

  for (E* p = g[u]; p; p = p->next)

    if (!p->vis) {

      p->vis = p->rev->vis = true;

      if (!vis[p->v]) {

        dfs(p->v);

        if (par[p->v]) {

          printf("%d %d\n", p->v, u);

        } else {

          printf("%d %d\n", u, p->v);

          par[u] ^= 1;

        }

      } else {

        printf("%d %d\n", u, p->v);

        par[u] ^= 1;

      }

    }

}



int main() {

  scanf("%d%d", &n, &m);

  if (m % 2) {

    puts("-1");

    return 0;

  }

  while (m--) {

    int u, v;

    scanf("%d%d", &u, &v);

    E *p = adde(u, v), *q = adde(v, u);

    p->rev = q;

    q->rev = p;

  }

  dfs(1);

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define fi first

#define se second

using namespace std;

long long n,m;

const long long N=1e5+5;

bool vs[N];

vector<long long> adj[N];

vector<long long> nadj[N];

vector<pair<long long,long long> > ans;

long long odd[N];

vector<pair<long long, long long> > inp;

map<long long, map<long long, long long> > edge;

void dfs(long long e){

	vs[e]=true;

	for(auto x: adj[e]){

		if(vs[x]==false){

			edge[e][x]=1;

			edge[x][e]=1;

			dfs(x);

			nadj[e].push_back(x);

		}

	}

}

void DFS(long long e, long long par){

	vs[e]=true;

	for(auto x: nadj[e]){

		DFS(x,e);

	}

	if(odd[e]==0&&e!=1){

		odd[par] = (odd[par]+1)%2;

		ans.push_back({par,e});

	}

	else if(e!=1&&odd[e]==1){

		odd[e] = (odd[e]+1)%2;

		ans.push_back({e,par});

	}

}

signed main(){

	cin >> n >> m;

	for(int i=1;i<=m;i++){

		long long a,b;

		cin >> a >> b;

		adj[a].push_back(b);

		adj[b].push_back(a);

		inp.push_back({a,b});

	}

	if(m%2==1){

		cout << "-1";

		return 0;

	}

	dfs(1);

	for(auto x:inp){

		if(edge[x.fi][x.se]==0){

			odd[x.fi] = (odd[x.fi]+1)%2;

			ans.push_back({x.fi,x.se});

		}

	}

	memset(vs,false,sizeof(vs));

	DFS(1,1);

	if(odd[1]==1){

		cout << "-1";

	}

	else{

		for(auto x : ans){

			cout << x.fi << " " << x.se<<endl;

		}

	}

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

#include<cmath>

#include<vector>

const int maxn=1e5+1000;

using namespace std;

int n,m,fa[maxn],out[maxn];

vector<int>side[maxn];

int get(int x){

	if(fa[x]==x)return x;

	fa[x]=get(fa[x]);

	return fa[x];	

}

void uni(int x,int y){

	fa[get(x)]=get(y);	

}

void dfs(int now,int fa){

	for(int i=0;i<side[now].size();i++){

		int v=side[now][i];if(v==fa)continue;

		dfs(v,now);

		if(out[v]&1){printf("%d %d\n",v,now);}

		else{out[now]++;printf("%d %d\n",now,v);}	

	}

	return;

}

int main(){

	scanf("%d%d",&n,&m);

	if(m&1){printf("-1");return 0;}

	for(int i=1;i<=n;i++)fa[i]=i;

	for(int i=1;i<=m;i++){

		int u,v;scanf("%d%d",&u,&v);

		if(get(u)!=get(v)){side[u].push_back(v);side[v].push_back(u);uni(u,v);}

		else{

			out[v]++;

			printf("%d %d\n",v,u);

		}

	}//

	dfs(1,0);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

#define fi first

#define se second

const int N=1e5+5;

int n,m,u[N],v[N],check[N],deg[N];

vector<pair<int,int> > ans;

vector<int> adj[N];

map<pair<int,int>,int> dir;

void dfs(int u,int p){

	check[u]=1;

	for(int v: adj[u]){

		if(check[v]==0){

			dfs(v,u);

		}

	}

	if(deg[u]%2==1){

		if(dir[{u,p}]==1){

			dir[{u,p}]=0;

			dir[{p,u}]=1;

			deg[u]--;

			deg[p]++;

		}else{

			dir[{u,p}]=1;

			dir[{p,u}]=0;

			deg[u]++;

			deg[p]--;

		}

	}

}

int main(){

	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	cin>>n>>m;

	for(int i=1;i<=m;i++){

		cin>>u[i]>>v[i];

		adj[u[i]].push_back(v[i]);

		adj[v[i]].push_back(u[i]);

		dir[{u[i],v[i]}]=1;

		deg[u[i]]++;

	}

	if(m%2==1){

		cout<<"-1";

		return 0;

	}

	dfs(1,1);

	for(int i=1;i<=m;i++){

		if(dir[{u[i],v[i]}]==1){

			cout<<u[i]<<" "<<v[i]<<endl;

		}else{

			cout<<v[i]<<" "<<u[i]<<endl;

		}

	}

}

// Optimized solution to the same problem (faster):
#include<iostream>

#include<algorithm>

#include<cstring>

#include<cstdio>

using namespace std;

#define MAXN 200006

int n , m;



int head[MAXN] , to[MAXN << 1] , nex[MAXN << 1] , ecn = -1;

void ade( int u , int v ) {

	to[++ecn] = v , nex[ecn] = head[u] , head[u] = ecn;

}

int fa[MAXN];

int find( int x ) {

	return fa[x] == x ? x : fa[x] = find( fa[x] );

}

struct e{ int u , v; } E[MAXN];

int tt[MAXN] , deg[MAXN];

void dfs( int u , int fa , int ee ) {

	for( int i = head[u] ; ~ i ; i = nex[i] ) {

		int v = to[i];

		if( v == fa ) continue;

		dfs( v , u , i );

	}

	if( u == 1 ) return;

	if( deg[u] ) {

		deg[u] ^= 1;

		if( ~ ee & 1 ) 

			swap( E[tt[ee >> 1]].u , E[tt[ee >> 1]].v );

	} else {

		deg[fa] ^= 1;

		if( ee & 1 ) 

			swap( E[tt[ee >> 1]].u , E[tt[ee >> 1]].v );

	}

}

int main() {

	memset( head , -1 , sizeof head );

	cin >> n >> m;

	if( m & 1 ) return puts("-1") , 0;

	for( int i = 1 ; i <= n ; ++ i ) fa[i] = i;

	for( int i = 1 , u , v ; i <= m ; ++ i ) {

		scanf("%d%d",&u,&v);

		E[i] = ( e ) { u , v };

		if( find( u ) != find( v ) ) {

			ade( u , v ) , ade( v , u );

			tt[ecn >> 1] = i;

			fa[find( u )] = find( v );

		} else {

			deg[u] ^= 1;

		}

	}

	dfs( 1 , 1 , 0 );

	for( int i = 1 ; i <= m ; ++ i ) printf("%d %d\n",E[i].u , E[i].v);

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



//#pragma GCC optimize("O3")

//#pragma GCC target("sse4")



#define FOR(i, a, b) for(int i = (a); i < (b); ++i)

#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)

#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)

#define FILL(a, value) memset(a, value, sizeof(a))



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

#define ALL(a) a.begin(), a.end()

#define PB push_back

#define MP make_pair



typedef long long LL;

typedef pair<int, int> PII;



const double PI = acos(-1.0);

const int INF = 1000 * 1000 * 1000 + 7;

const LL LINF = (LL)INF * INF;



const int MAX = 1 << 17;



vector<int> g[MAX];

bool used[MAX];

bool cnt[MAX];

vector<PII> ans;

int dep[MAX];



void dfs(int v, int p)

{

	used[v] = true;

	for(int to: g[v])

	{

		if(used[to] && to != p && dep[to] < dep[v])

		{

			ans.PB(MP(v, to));

			cnt[v] ^= 1;

		}

		if(!used[to])

		{

			dep[to] = dep[v] + 1;

			dfs(to, v);

			if(cnt[to])

				ans.PB(MP(to, v));

			else

			{

				ans.PB(MP(v, to));

				cnt[v] ^= 1;

			}

		}

	}

}



int main()

{

	//ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n, m;

	cin >> n >> m;

	if(m & 1)

	{

		cout << -1;

		return 0;

	}

	FOR(i, 0, m)

	{

		int u, v;

		cin >> u >> v;

		u--;

		v--;

		g[u].PB(v);

		g[v].PB(u);

	}

	dfs(0, -1);

	assert(SZ(ans) == m);

	for(auto e: ans)

		cout << e.first + 1 << " " << e.second + 1 << "\n";

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 7;

int n, m, d[maxn], fa[maxn];



int find(int x) {

	return x == fa[x]? x : fa[x] = find(fa[x]);

}



int fir[maxn], nxt[maxn], to[maxn], e = 0;

void add(int x, int y) {

	to[++e] = y; nxt[e] = fir[x]; fir[x] = e;

	to[++e] = x; nxt[e] = fir[y]; fir[y] = e;

}



int num[maxn];

void dfs(int pos, int f) {

	int y, z;

	for (y = fir[pos]; y; y = nxt[y]) {

		if((z = to[y]) == f) continue;

		dfs(z, pos);

		num[pos] ^= num[z];

	}

	if(pos > 1) {

		if(num[pos]) printf("%d %d\n", f, pos);

		else printf("%d %d\n", pos, f);

	}

}



int main() {

	scanf("%d%d", &n, &m);

	if(m & 1) {

		printf("-1\n");

		return 0;

	}

	for (int i = 1; i <= n; ++i) fa[i] = i;

	int x, y;

	for (int i = 1; i <= m; ++i) {

		scanf("%d%d", &x, &y);

		if(find(x) == find(y)) {

			printf("%d %d\n", x, y);

			d[x] ^= 1;

		}

		else {

			fa[find(x)] = find(y);

			add(x, y);

		}

	}

	if(d[1]) num[1] = 1;

	for (int i = 2; i <= n; ++i) {

		d[i] ^= 1;

		if(d[i]) {

			num[i] = 1;

		}

	}

	dfs(1, 0);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<cstdio>

#include<algorithm>

#include<cstring>

#include<cmath>

#include<vector>

const int maxn=1e5+1000;

using namespace std;

int n,m,fa[maxn],out[maxn];

vector<int>side[maxn];

int get(int x){

	if(fa[x]==x)return x;

	fa[x]=get(fa[x]);

	return fa[x];	

}

void uni(int x,int y){

	fa[get(x)]=get(y);	

}

void dfs(int now,int fa){

	for(int i=0;i<side[now].size();i++){

		int v=side[now][i];if(v==fa)continue;

		dfs(v,now);

		if(out[v]&1){printf("%d %d\n",v,now);}

		else{out[now]++;printf("%d %d\n",now,v);}	

	}

	return;

}

int main(){

	scanf("%d%d",&n,&m);

	if(m&1){printf("-1");return 0;}

	for(int i=1;i<=n;i++)fa[i]=i;

	for(int i=1;i<=m;i++){

		int u,v;scanf("%d%d",&u,&v);

		if(get(u)!=get(v)){side[u].push_back(v);side[v].push_back(u);uni(u,v);}

		else{

			out[v]++;

			printf("%d %d\n",v,u);

		}

	}

	dfs(1,0);

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 7;

int n, m, d[maxn], fa[maxn];



int find(int x) {

	return x == fa[x]? x : fa[x] = find(fa[x]);

}



int fir[maxn], nxt[maxn], to[maxn], e = 0;

void add(int x, int y) {

	to[++e] = y; nxt[e] = fir[x]; fir[x] = e;

	to[++e] = x; nxt[e] = fir[y]; fir[y] = e;

}



int num[maxn];

void dfs(int pos, int f) {

	int y, z;

	for (y = fir[pos]; y; y = nxt[y]) {

		if((z = to[y]) == f) continue;

		dfs(z, pos);

		num[pos] ^= num[z];

	}

	if(pos > 1) {

		if(num[pos]) printf("%d %d\n", f, pos);

		else printf("%d %d\n", pos, f);

	}

}



int main() {

	scanf("%d%d", &n, &m);

	if(m & 1) {

		printf("-1\n");

		return 0;

	}

	for (int i = 1; i <= n; ++i) fa[i] = i;

	int x, y;

	for (int i = 1; i <= m; ++i) {

		scanf("%d%d", &x, &y);

		if(find(x) == find(y)) {

			printf("%d %d\n", x, y);

			d[x] ^= 1;

		}

		else {

			fa[find(x)] = find(y);

			add(x, y);

		}

	}

	if(d[1]) num[1] = 1;

	for (int i = 2; i <= n; ++i) {

		d[i] ^= 1;

		if(d[i]) {

			num[i] = 1;

		}

	}

	dfs(1, 0);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



const int maxn = 1e5 + 20;



bool visited[maxn];

int n, m, a, b, outDegree[maxn], dis[maxn];

vector<int> graph[maxn];



void dfs(int i) {

    visited[i] = 1;

    for (int x : graph[i]) {

        if (!visited[x]){

            dis[x] = dis[i] + 1; 

            dfs(x);

        }

        if (dis[x] > dis[i]) {

            if (outDegree[x] % 2 == 0){

                outDegree[i]++;

                cout << i << " " << x << endl;

            }

            else{

                outDegree[x] ++;

                cout << x << ' '  << i << endl;

            }

        }

    }

}

int main() {

    int n, m;

    cin >> n >> m;

    if (m % 2 == 1)

        return cout << -1 << endl, 0;

    for (int i = 0; i < m; i++) {

        cin >> a >> b;

        graph[a].push_back(b);

        graph[b].push_back(a);

    }



    dfs(1);    

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 7;

int n, m, d[maxn], fa[maxn];



int find(int x) {

	return x == fa[x]? x : fa[x] = find(fa[x]);

}



int fir[maxn], nxt[maxn], to[maxn], e = 0;

void add(int x, int y) {

	to[++e] = y; nxt[e] = fir[x]; fir[x] = e;

	to[++e] = x; nxt[e] = fir[y]; fir[y] = e;

}



int num[maxn];

void dfs(int pos, int f) {

	int y, z;

	for (y = fir[pos]; y; y = nxt[y]) {

		if((z = to[y]) == f) continue;

		dfs(z, pos);

		num[pos] ^= num[z];

	}

	if(pos > 1) {

		if(num[pos]) printf("%d %d\n", f, pos);

		else printf("%d %d\n", pos, f);

	}

}



int main() {

	scanf("%d%d", &n, &m);

	if(m & 1) {

		printf("-1\n");

		return 0;

	}

	for (int i = 1; i <= n; ++i) fa[i] = i;

	int x, y;

	for (int i = 1; i <= m; ++i) {

		scanf("%d%d", &x, &y);

		if(find(x) == find(y)) {

			printf("%d %d\n", x, y);

			d[x] ^= 1;

		}

		else {

			fa[find(x)] = find(y);

			add(x, y);

		}

	}

	if(d[1]) num[1] = 1;

	for (int i = 2; i <= n; ++i) {

		d[i] ^= 1;

		if(d[i]) {

			num[i] = 1;

		}

	}

	dfs(1, 0);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



typedef long long               ll;

typedef unsigned long long      ull;



const int N = 100 * 1000 + 20;



vector <ll> adj[N];

bool vis[N];

ll d[N], outD[N];



void dfs(ll v) {

    vis[v] = true;

    for (auto u: adj[v]) {

        if (!vis[u]) {

            d[u] = d[v] + 1;

            dfs(u);

        }

        if (d[u] > d[v]) {

            if (!(outD[u] & 1)) {

                outD[v]++;

                cout << v << " " << u << endl;

            }

            else {

                outD[u]++;

                cout << u << ' '  << v << endl;

            }

        }

    }

}



int main() {

    ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);

    ll n, m;

    cin >> n >> m;

    if (m & 1)

        return cout << -1 << endl, 0;

    for (int i = 0, u, v; i < m; i++) {

        cin >> v >> u;

        adj[v].push_back(u);

        adj[u].push_back(v);

    }

    dfs(1);

    return 0;

}


// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 7;

int n, m, d[maxn], fa[maxn];



int find(int x) {

	return x == fa[x]? x : fa[x] = find(fa[x]);

}



int fir[maxn], nxt[maxn], to[maxn], e = 0;

void add(int x, int y) {

	to[++e] = y; nxt[e] = fir[x]; fir[x] = e;

	to[++e] = x; nxt[e] = fir[y]; fir[y] = e;

}



int num[maxn];

void dfs(int pos, int f) {

	int y, z;

	for (y = fir[pos]; y; y = nxt[y]) {

		if((z = to[y]) == f) continue;

		dfs(z, pos);

		num[pos] ^= num[z];

	}

	if(pos > 1) {

		if(num[pos]) printf("%d %d\n", f, pos);

		else printf("%d %d\n", pos, f);

	}

}



int main() {

	scanf("%d%d", &n, &m);

	if(m & 1) {

		printf("-1\n");

		return 0;

	}

	for (int i = 1; i <= n; ++i) fa[i] = i;

	int x, y;

	for (int i = 1; i <= m; ++i) {

		scanf("%d%d", &x, &y);

		if(find(x) == find(y)) {

			printf("%d %d\n", x, y);

			d[x] ^= 1;

		}

		else {

			fa[find(x)] = find(y);

			add(x, y);

		}

	}

	if(d[1]) num[1] = 1;

	for (int i = 2; i <= n; ++i) {

		d[i] ^= 1;

		if(d[i]) {

			num[i] = 1;

		}

	}

	dfs(1, 0);

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



#define lli long long int

#define REP(i,n) for(int i=0;i<n;i++)

#define REP2(i,n) for(lli i=1;i<=n;i++)



#define DEBUG 0



int main(){

	

	lli n,q;

	string s;

	char d[4] = {'A','T','C','G'};

	cin>>n>>q;

	cin>>s;



	lli data[100010]={0};

	for(lli i=0;i<n-1;i++){

		if(s.at(i) == 'A' && s.at(i+1)=='C'){

			data[i]=1;

		}

	}

	for(lli i=n-1;i>=0;i--){

		data[i] += data[i+1];

	}

	REP(i,n)if(DEBUG)cout<<"i="<<i<<" data = "<<data[i]<<endl;

	REP(i,q){

		lli l,r;

		cin>>l>>r;

		l--;

		r--;

		cout<<data[l]-data[r]<<endl;

	}

	return 0;

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



#define lli long long int

#define REP(i,s,n) for(int i=s;i<n;i++)

#define MOD 1000000007

#define NUM 2520

#define INF (1LL<<50)

#define DEBUG 0

#define mp(a,b) make_pair(a,b)

#define SORT(V) sort(V.begin(),V.end())

#define PI (3.141592653589794)



lli d[100100];



void func(long long N, long long Q, std::string S, std::vector<long long> l, std::vector<long long> r){



    REP(i,0,N-1){

        if(S[i]=='A' &&S[i+1]=='C'){

            d[i]++;

        }

    }



    REP(i,0,N-1){

        d[i+1]+=d[i];

    }





    REP(i,0,Q){

        cout<<(d[r[i]-1]-d[l[i]-1])<<endl;

    }



}



int main(){

    // cout << fixed << setprecision(5);



    long long N;

    scanf("%lld",&N);

    long long Q;

    scanf("%lld",&Q);

    std::string S;

    std::cin >> S;

    std::vector<long long> l(Q);

    std::vector<long long> r(Q);

    for(int i = 0 ; i < Q ; i++){

        scanf("%lld",&l[i]);

        scanf("%lld",&r[i]);

        l[i]--,r[i]--;

    }

    func(N, Q, S, std::move(l), std::move(r));

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;

int t[100000],n,k,a,b;

string s;

int main(void){

    cin>>n>>k>>s;

    for(int i=0;i<n-1;i++){

        if(s[i]=='A'&&s[i+1]=='C')t[i+1]=1;

    }

    for(int i=0;i<100000;i++)t[i+1]+=t[i];

    for(int i=0;i<k;i++){

        cin>>a>>b;

        cout<<t[b-1]-t[a-1]<<endl;

    }

}


// Optimized solution to the same problem (faster):
#include <iostream>

using namespace std;

int n,k,a,b,t[100000];

string s;

int main(void){

    cin>>n>>k>>s;

    for(int i=0;i<n-1;i++){

        if(s[i]=='A'&&s[i+1]=='C')t[i+1]=1;

        t[i+1]+=t[i];

    }

    

    for(int i=0;i<k;i++){

        cin>>a>>b;

        cout<<t[b-1]-t[a-1]<<endl;

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <vector>



using namespace std;



int main()

{

	int N, Q, ans;

	

	cin >> N >> Q;

	

	string S;

	

	cin >> S;

	

	vector<int> l(Q), r(Q);

	

	for (int i = 0; i < Q; i++) {

		cin >> l[i] >> r[i];

	}

	

	vector<int> t(N, 0);

	

	for (int i = 0; i < N; i++) {

		if (S[i] == 'A' && S[i + 1] == 'C') {

			t[i + 1] += t[i] + 1;

		}

		else {

			t[i + 1] = t[i];

		}

	}

	

	for (int i = 0; i < Q; i++) {

		cout << t[r[i] - 1] - t[l[i] - 1] << endl;

	}

}


// Optimized solution to the same problem (faster):
#include<stdio.h>



int N, Q;

char S[100001];



int acCount[100000];

int sum[100001];

int main(){

	scanf("%d%d",&N, &Q);

	scanf("%s",S);



	for(int i = 0; i < N; i++){

		if(S[i] == 'A' and S[i + 1] == 'C'){

			sum[i + 1] += 1 + sum[i];

		}

		else{

			sum[i + 1] = sum[i];

		}

	}

	for(int i = 0; i < Q; i++){

		int l, r;

		scanf("%d%d",&l, &r);

		printf("%d\n", sum[r - 1] - sum[l - 1]);

	}

	return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

#include <string>

#include <vector> 

using namespace std;

 

int main() {

  ios::sync_with_stdio(false);

  int N, Q;

  string S;

  cin >> N >> Q >> S;

  

  vector<int> sum(S.size()+1, 0);

  // 0 0 1

  for(int i = 1; i < S.size(); i++)

    sum[i+1] = sum[i] + (S[i-1] == 'A' && S[i] == 'C');

  

  while(Q--) {

    int l, r;

    cin >> l >> r;

    cout << sum[r] - sum[l] << "\n";

  }

  return 0;

}

// Optimized solution to the same problem (faster):
#include <cstdio>

#include <string>

#include <vector> 

using namespace std;



char S[100000+1];

int sum[100000+1];

int main() {

  int N, Q;

  scanf("%d %d %s", &N, &Q, S);

  for(int i = 1; i < N; i++)

    sum[i+1] = sum[i] + (S[i-1] == 'A' && S[i] == 'C');

  while(Q--) {

    int l, r;

    scanf("%d %d", &l, &r);

    printf("%d\n", sum[r] - sum[l]);

  }

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <iostream>

using namespace std;



char txt[100001];

int dp[100001];

int main(){

	int N,Q;

	cin >> N >> Q;

	cin >> txt;

	for(int i=1;i<N;i++){

		if(txt[i]=='C'&&txt[i-1]=='A') dp[i]++;

		dp[i]+=dp[i-1];

	}

	while(Q--){

		int l,r;

		cin >> r >> l;

		cout << dp[l-1]-dp[r-1] << "\n";

	}

}




// Optimized solution to the same problem (faster):
#include <stdio.h>



int main(){

    int N, Q;

    int n = 0;

    int l, r;

    scanf("%d %d", &N, &Q);

    char s[N];

    int t[N];

    scanf("%s", s);

    t[0]=0;

    for ( int i = 0; i < N-1 ; i++ ){

        if (s[i]=='A' && s[i+1] =='C'){

            n++;

        }

        t[i+1]=n;

    } 

    for ( int i = 0; i < Q ; i++ ){

        scanf("%d %d", &l, &r);

        printf("%d\n", t[r-1] - t[l-1]);

    }

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#ifdef __GNUC__

#include <bits/stdc++.h>

#endif // __GNUC__





int main() {

    int N,Q; std::cin >> N >> Q;

    std::string S; std::cin >> S;

    std::vector<int> counts(N, 0);

    std::vector<int> ans(Q);

    int count = 0;

    for (int i = 0; i < N - 1; ++i) {

        if (S[i] == 'A' && S[i + 1] == 'C')counts[i + 1] = ++count;

        else counts[i + 1] = count;

    }

    for (int i = 0; i < Q; ++i) {

        int l, r; std::cin >> l >> r;

        ans[i] = counts[r - 1] - counts[l - 1];

    }

    for (auto& v : ans)std::cout << v << std::endl;

}

// Optimized solution to the same problem (faster):
#include <stdio.h>

#include <stdlib.h>

int main() {

    int N,Q;

    char S[100001];

    int counts[100001];//i番目までにACが何回現れたか

    int ans[100001];

    int l, r;

    int count = 0;

    scanf("%d",&N);

    scanf("%d",&Q);

    scanf("%s",S);

    //ACが現れた回数をcountsに保存する

    //forの範囲に注意

    for (int i = 0; i < N - 1; ++i) {

        if (S[i] == 'A' && S[i + 1] == 'C')++count;

        counts[i + 1] = count;

    }

    //答えの計算

    for (int i = 0; i < Q; ++i) {

        scanf("%d",&l);

        scanf("%d",&r);

        ans[i] = counts[r - 1] - counts[l - 1];

    }

    for (int i = 0; i < Q; ++i)

    	printf("%d\n", ans[i]);

}


// Fastest known solution for this problem: