#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 1000005
struct st
{
    int x,y,num;
    char ch;
}p[N];
int sum[N];
bool fan(struct st A,struct st B)
{
    if(A.x < B.x)
    return true;
    return false;
}
bool gn(struct st A,struct st B)
{
    if(A.num < B.num)
    return true;
    return false;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i = 1;i <= n;i ++)
        {
            scanf("%d %d",&p[i].x,&p[i].y);
            p[i].num = i;
        }
//        if(n == 1)
//        {
//            if(p[0].x < p[i].y)
//            puts("A");
//            else
//            puts("G");
//            continue;
//        }
        sort(p + 1,p + n + 1,fan);
        sum[1] = p[1].x;
        for(int i = 2;i <= n;i ++)
        sum[i] = sum[i - 1] + p[i].x;
        int max = 1000000009,v,k,s;
        for(int i = 0;i <= n;i ++)
        {
            v = 1000 * (n - i) - (sum[n] - sum[i]);
            s = fabs(v - sum[i]);
            if(s < max)
            {
                max = s;
                k = i;
            }
        }
        for(int i = 1;i <= k;i ++)
        p[i].ch = 'A';
        for(int i = k + 1;i <= n;i ++)
        p[i].ch = 'G';
        sort(p + 1,p + n + 1,gn);
        if(max > 500)
        {printf("-1\n");}
        else
        {for(int i = 1;i <= n;i ++)
        printf("%c",p[i].ch);
        printf("\n");}

    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 1000005
struct st
{
    int x,y,num;
    char ch;
}p[N];
int sum[N];
bool fan(struct st A,struct st B)
{
    if(A.x < B.x)
    return true;
    return false;
}
bool gn(struct st A,struct st B)
{
    if(A.num < B.num)
    return true;
    return false;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i = 0;i < n;i ++)
        {
            scanf("%d %d",&p[i].x,&p[i].y);
            p[i].num = i;
        }
        sort(p,p + n,fan);
        sum[0] = p[0].x;
        for(int i = 1;i < n;i ++)
        sum[i] = sum[i - 1] + p[i].x;
        int max = 1000000009,v,k,s;
        for(int i = 0;i < n;i ++)
        {
            v = 1000 * (n - 1 - i) - (sum[n - 1] - sum[i]);
            s = fabs(v - sum[i]);
            if(s < max)
            {
                max = s;
                k = i;
            }
        }
        for(int i = 0;i <= k;i ++)
        p[i].ch = 'A';
        for(int i = k + 1;i < n;i ++)
        p[i].ch = 'G';
        sort(p,p + n,gn);
        if(max > 500)
        {printf("-1\n");}
        else
        {for(int i = 0;i < n;i ++)
        printf("%c",p[i].ch);
        printf("\n");}

    }
    return 0;
}


#include <cstdio>
#include <cmath>
#define N 1000005
int a[N],b[N];
char ch[N];
int main()
{
    int t;
    while(~scanf("%d",&t))
    {
        for(int i = 0;i < t;i ++)
        scanf("%d %d",&a[i],&b[i]);
        int sum1 = 0,sum2 = 0;
        for(int i = 0;i < t;i ++)
        {
            if(sum1 >= sum2)
            {
                sum2 += b[i];
                ch[i] = 'G';
            }
            else
            {
                sum1 += a[i];
                ch[i] = 'A';
            }
        }
        ch[t] = '\0';
        int s = fabs(sum1 - sum2);
        if(s <= 500)
        printf("%s\n",ch);
        else
        printf("-1\n");
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#define N 1000005
int a[N],b[N];
char ch1[N],ch2[N];
int main()
{
    int t;
    while(~scanf("%d",&t))
    {
        for(int i = 0;i < t;i ++)
        scanf("%d %d",&a[i],&b[i]);
        int sum1 = 0,sum2 = 0,sum3 = 0,sum4 = 0;
        for(int i = 0;i < t;i ++)
        {
            if(sum1 >= sum2)
            {
                sum2 += b[i];
                ch1[i] = 'G';
            }
            else
            {
                sum1 += a[i];
                ch1[i] = 'A';
            }
            if(sum3 <= sum4)
            {
                sum3 += a[i];
                ch2[i] = 'A';
            }
            else
            {
                sum4 += b[i];
                ch2[i] = 'G';
            }
        }
        ch1[t] = '\0';
        ch2[t] = '\0';
        int s1 = fabs(sum1 - sum2),s2 = fabs(sum3 - sum4);
        if(s2 <= 500)
        printf("%s\n",ch2);
        else if(s1 <= 500)
        printf("%s\n",ch1);
        else
        printf("-1\n");
    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 1000005
struct st
{
    int x,y,num;
    char ch;
}p[N];
int sum[N];
bool fan(struct st A,struct st B)
{
    if(A.x < B.x)
    return true;
    return false;
}
bool gn(struct st A,struct st B)
{
    if(A.num < B.num)
    return true;
    return false;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i = 0;i < n;i ++)
        {
            scanf("%d %d",&p[i].x,&p[i].y);
            p[i].num = i;
        }
        sort(p,p + n,fan);
        sum[0] = p[0].x;
        for(int i = 1;i < n;i ++)
        sum[i] = sum[i - 1] + p[i].x;
        int max = 2000000009,v,k,s;
        for(int i = 0;i < n;i ++)
        {
            v = 1000 * (n - 1 - i) - (sum[n - 1] - sum[i]);
            s = fabs(v - sum[i]);
            if(s < max)
            {
                max = s;
                k = i;
            }
        }
        for(int i = 0;i <= k;i ++)
        p[i].ch = 'A';
        for(int i = k + 1;i < n;i ++)
        p[i].ch = 'G';
        sort(p,p + n,gn);
        if(max <= 500)
        {printf("-1\n");continue;}
        for(int i = 0;i < n;i ++)
        printf("%c",p[i].ch);
        printf("\n");

    }
    return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
#define N 1000005
struct st
{
    int x,y,num;
    char ch;
}p[N];
int sum[N];
bool fan(struct st A,struct st B)
{
    if(A.x < B.x)
    return true;
    return false;
}
bool gn(struct st A,struct st B)
{
    if(A.num < B.num)
    return true;
    return false;
}
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        for(int i = 0;i < n;i ++)
        {
            scanf("%d %d",&p[i].x,&p[i].y);
            p[i].num = i;
        }
        sort(p,p + n,fan);
        sum[0] = p[0].x;
        for(int i = 1;i < n;i ++)
        sum[i] = sum[i - 1] + p[i].x;
        int max = 1000000009,v,k,s;
        for(int i = 0;i < n;i ++)
        {
            v = 1000 * (n - 1 - i) - (sum[n - 1] - sum[i]);
            s = fabs(v - sum[i]);
            if(s < max)
            {
                max = s;
                k = i;
            }
        }
        for(int i = 0;i <= k;i ++)
        p[i].ch = 'A';
        for(int i = k + 1;i < n;i ++)
        p[i].ch = 'G';
        sort(p,p + n,gn);
        for(int i = 0;i < n;i ++)
        printf("%c",p[i].ch);
        printf("\n");

    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
main()
{

      int n,i,a,b,s=0,m,c,x=0;
      char ss[1000001];
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            scanf("%d%d",&a,&b);
            m=0;c=0;
            if(s+a<=500){s=s+a;m=1;x++;}
            else{
            if(m==0&&s-b>=-500){s=s-b;c=1;}}
            if(m)ss[i-1]='A';
            if(c)ss[i-1]='G';

      }
            if(x==n||x==0){printf("-1");return 0;}
            for(i=0;i<n;i++){printf("%c",ss[i]);}
      return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
main()
{
      int n,i,a,b,s=0,x=0;
      char ss[1000001];
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            scanf("%d%d",&a,&b);
            if(s+a<=500){ss[i-1]='A';s=s+a;x++;}
            else{ss[i-1]='G';s=s-b;}

      }
     if(x==0||x==n)printf("-1");
     for(i=0;i<n;i++)printf("%c",ss[i]);
      return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
main()
{
      int n,i,a,b,s=0,x=0;
      char ss[1000001];
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            scanf("%d%d",&a,&b);
            if(s+a<=500){ss[i-1]='A';s=s+a;x++;}
            else{ss[i-1]='G';s=s-b;}

      }

     for(i=0;i<n;i++)printf("%c",ss[i]);
      return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
main()
{

      int n,i,a,b,s=0,m,c,x=0;
      char ss[1000001];
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            scanf("%d%d",&a,&b);
            m=0;c=0;
            if(s+a<=500){ss[i-1]='A';s=s+a;m=1;x++;}
            else{
            if(m==0&&s-b>=-500){ss[i-1]='G';s=s-b;c=1;}}

      }
            if(x==n||x==0){printf("-1");return 0;}
            for(i=0;i<n;i++){printf("%c",ss[i]);}
      return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
main()
{
      int n,i,a,b,s=0;

      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            scanf("%d%d",&a,&b);
            if(s+a<=500){printf("A");s=s+a;}
            else{printf("G");s=s-a;}

      }

      return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
main()
{
      freopen("1.in","r",stdin);
      freopen("1.out","w",stdout);
      int n,i,a,b,s=0,m,c,x=0;
      char ss[1000001];
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            scanf("%d%d",&a,&b);
            m=0;c=0;
            if(s+a<=500){ss[i-1]='A';s=s+a;m=1;x++;}
            else{
            if(m==0&&s-b>=-500){ss[i-1]='G';s=s-b;c=1;}}

      }
            if(x==n||x==0){printf("-1");return 0;}
            for(i=0;i<n;i++){printf("%c",ss[i]);}
      return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
main()
{
      int n,i,a,b,s=0,x=0;

      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            scanf("%d%d",&a,&b);
            if(s+a<=500){ss[i-1]='A';s=s+a;x++;}
            else{ss[i-1]='G';s=s-b;}

      }
     if(x==0||x==n)printf("-1");
     for(i=0;i<n;i++)printf("%c",ss[i]);
      return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
main()
{
      int n,i,a,b,s=0,x=0;
      char ss[1000001];
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            scanf("%d%d",&a,&b);
            if(s+a<=500){ss[i-1]='A';s=s+a;x++;}
            else{ss[i-1]='G';s=s-a;}

      }
     if(x==0||x==n)printf("-1");
     for(i=0;i<n;i++)printf("%c",ss[i]);
      return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
main()
{
      int n,i,a,b,s=0,x=0;
      char ss[1000001];
      scanf("%d",&n);
      for(i=1;i<=n;i++)
      {
            scanf("%d%d",&a,&b);
            if(s+a<=500){ss[i-1]='A';s=s+a;x++;}
            else{ss[i-1]='G';s=s-a;}

      }
     //if(x==0||x==n)printf("-1");
     for(i=0;i<n;i++)printf("%c",ss[i]);
      return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef signed long long int lli;
#define ip(n) scanf("%d",&n)
#define For(i,n) for(i;i<n;i++)
#define INF 99999999
#define VERT 1
vector< vector<pair<int,int> > > graph = vector <vector<pair<int, int> > > (5000+1);
vector<int> visited = vector<int> (VERT+1,0), parent = vector<int> (VERT + 1);
vector<int> dist=vector<int> (VERT + 1);

void Dijkstra(int source,int n)//n is the no. of vertices;
{
    for(int i=1;i<=n;i++)// Initially setting shortest distance of each vertex from the source vertex to be infinity
        dist[i]=INT_MAX;

    dist[source]=0;

    priority_queue<pair<int,int>, vector<pair<int,int> >,std::greater<pair<int,int> > >p;
    p.push(make_pair(0,source));
 	parent[source] = -1;
    while(p.empty()==false)
    {
        pair<int,int> current = p.top();
        p.pop();
        int cv=current.second;//current vertex which has been extracted out from min heap
        int cw=current.first;//current min dist till this vertex from the source

        if(visited[cv]==1)//if the node is already visited then continue;
            continue;

        visited[cv]=1;//mark the node as visited

        for(vector<pair<int,int> >::iterator itr=graph[cv].begin();itr!=graph[cv].end();itr++)
        {
             if(visited[itr->second]==0&&dist[itr->second]>cw+itr->first)
             {
             	parent[itr->second] = cv;
             	dist[itr->second]=cw+itr->first;
            	p.push(make_pair(dist[itr->second],itr->second));
             }
        }
    }
}
 void printPath(int j)
{
    // Base Case : If j is source
    if (parent[j]==-1)
    {
    	cout<<j<<" ";
        return;
	}
    printPath(parent[j]);
    printf("%d ", j);
}

int a[1000003], b[1000003],n;
char arr[1000003];
int calc(int i, lli sa, lli sb)
{
	if(i==n && sa-sb<501)
	{
		arr[i] = '\0';
		return 1;
	}
	if(sa-sb>0)
	{
		if((b[i] + sb <= sa  + 500)&&calc(i+1, sa, sb + b[i]))
		{
			arr[i] = 'G';
			return 1;
		}
		else if(( sa + a[i] <= sb + 500)&&calc(i+1, sa + a[i], sb))
		{
			arr[i] = 'A';
			return 1;
		}

		else
		return 0;
	}
	else if(sb-sa>0)
	{
		if((a[i] + sa <= sb  + 500) && calc(i+1, sa + a[i], sb ))
		{
			arr[i] = 'A';
			return 1;
		}
		else if(( sb + b[i] >= sa + 500) && calc(i+1, sa , b[i]+ sb))
		{
			arr[i] = 'G';
			return 1;
		}

		else
		return 0;
	}
	else
	{
		if(a[i]<501 && calc(i+1, sa + a[i], sb))
		{
			arr[i] = 'A';
			return 1;
		}else{
			arr[i] = 'G';
			return calc(i+1, sa, sb+b[i]);
		}
	}
}
int main()
{
    int i=0;
    ip(n);
    For(i,n)
    {
    	ip(a[i]);
    	ip(b[i]);
    }
    if(calc(0,0,0))
    printf("%s",arr);
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef signed long long int lli;
#define ip(n) scanf("%d",&n)
#define For(i,n) for(i;i<n;i++)
#define INF 99999999
#define VERT 1
vector< vector<pair<int,int> > > graph = vector <vector<pair<int, int> > > (5000+1);
vector<int> visited = vector<int> (VERT+1,0), parent = vector<int> (VERT + 1);
vector<int> dist=vector<int> (VERT + 1);

void Dijkstra(int source,int n)//n is the no. of vertices;
{
    for(int i=1;i<=n;i++)// Initially setting shortest distance of each vertex from the source vertex to be infinity
        dist[i]=INT_MAX;

    dist[source]=0;

    priority_queue<pair<int,int>, vector<pair<int,int> >,std::greater<pair<int,int> > >p;
    p.push(make_pair(0,source));
 	parent[source] = -1;
    while(p.empty()==false)
    {
        pair<int,int> current = p.top();
        p.pop();
        int cv=current.second;//current vertex which has been extracted out from min heap
        int cw=current.first;//current min dist till this vertex from the source

        if(visited[cv]==1)//if the node is already visited then continue;
            continue;

        visited[cv]=1;//mark the node as visited

        for(vector<pair<int,int> >::iterator itr=graph[cv].begin();itr!=graph[cv].end();itr++)
        {
             if(visited[itr->second]==0&&dist[itr->second]>cw+itr->first)
             {
             	parent[itr->second] = cv;
             	dist[itr->second]=cw+itr->first;
            	p.push(make_pair(dist[itr->second],itr->second));
             }
        }
    }
}
 void printPath(int j)
{
    // Base Case : If j is source
    if (parent[j]==-1)
    {
    	cout<<j<<" ";
        return;
	}
    printPath(parent[j]);
    printf("%d ", j);
}

lli a[1000003], b[1000003],n;
char arr[1000003];
int calc(int i, lli sa, lli sb)
{
	if(i==n && abs(sa-sb)<501)
	{
		arr[i] = '\0';
		return 1;
	}
	if(sa-sb>0)
	{
		if(((lli)b[i] + sb <= sa  + (lli)500)&&calc(i+1, sa, sb + (lli)b[i]))
		{
			arr[i] = 'G';
			return 1;
		}
		else if(( sa + (lli)a[i] <= sb + (lli)500)&&calc(i+1, sa + (lli)a[i], sb))
		{
			arr[i] = 'A';
			return 1;
		}

		else
		return 0;
	}
	else if(sb-sa>0)
	{
		if(((lli)a[i] + sa <= sb  + (lli)500) && calc(i+1, sa + (lli)a[i], sb ))
		{
			arr[i] = 'A';
			return 1;
		}
		else if(( sb + (lli)b[i] <= sa + (lli)500) && calc(i+1, sa , (lli)b[i]+ sb))
		{
			arr[i] = 'G';
			return 1;
		}

		else
		return 0;
	}
	else
	{
		if(a[i]<501 && calc(i+1, sa + a[i], sb))
		{
			arr[i] = 'A';
			return 1;
		}else{
			arr[i] = 'G';
			return calc(i+1, sa, sb+(lli)b[i]);
		}
	}
	return 0;
}
int main()
{
    int i=0;
    ip(n);
    For(i,n)
    {
    	ip(a[i]);
    	ip(b[i]);
    }
    if(calc(0,0,0))
    printf("%s",arr);
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef signed long long int lli;
#define ip(n) scanf("%d",&n)
#define For(i,n) for(i;i<n;i++)
#define INF 99999999
#define VERT 1
vector< vector<pair<int,int> > > graph = vector <vector<pair<int, int> > > (5000+1);
vector<int> visited = vector<int> (VERT+1,0), parent = vector<int> (VERT + 1);
vector<int> dist=vector<int> (VERT + 1);

void Dijkstra(int source,int n)//n is the no. of vertices;
{
    for(int i=1;i<=n;i++)// Initially setting shortest distance of each vertex from the source vertex to be infinity
        dist[i]=INT_MAX;

    dist[source]=0;

    priority_queue<pair<int,int>, vector<pair<int,int> >,std::greater<pair<int,int> > >p;
    p.push(make_pair(0,source));
 	parent[source] = -1;
    while(p.empty()==false)
    {
        pair<int,int> current = p.top();
        p.pop();
        int cv=current.second;//current vertex which has been extracted out from min heap
        int cw=current.first;//current min dist till this vertex from the source

        if(visited[cv]==1)//if the node is already visited then continue;
            continue;

        visited[cv]=1;//mark the node as visited

        for(vector<pair<int,int> >::iterator itr=graph[cv].begin();itr!=graph[cv].end();itr++)
        {
             if(visited[itr->second]==0&&dist[itr->second]>cw+itr->first)
             {
             	parent[itr->second] = cv;
             	dist[itr->second]=cw+itr->first;
            	p.push(make_pair(dist[itr->second],itr->second));
             }
        }
    }
}
 void printPath(int j)
{
    // Base Case : If j is source
    if (parent[j]==-1)
    {
    	cout<<j<<" ";
        return;
	}
    printPath(parent[j]);
    printf("%d ", j);
}

int a[1000003], b[1000003],n;
char arr[1000003];
int calc(int i, lli sa, lli sb)
{
	if(i==n && abs(sa-sb)<501)
	{
		arr[i] = '\0';
		return 1;
	}
	if(sa-sb>0)
	{
		if((b[i] + sb <= sa  + 500)&&calc(i+1, sa, sb + b[i]))
		{
			arr[i] = 'G';
			return 1;
		}
		else if(( sa + a[i] <= sb + 500)&&calc(i+1, sa + a[i], sb))
		{
			arr[i] = 'A';
			return 1;
		}

		else
		return 0;
	}
	else if(sb-sa>0)
	{
		if((a[i] + sa <= sb  + 500) && calc(i+1, sa + a[i], sb ))
		{
			arr[i] = 'A';
			return 1;
		}
		else if(( sb + b[i] >= sa + 500) && calc(i+1, sa , b[i]+ sb))
		{
			arr[i] = 'G';
			return 1;
		}

		else
		return 0;
	}
	else
	{
		if(a[i]<501 && calc(i+1, sa + a[i], sb))
		{
			arr[i] = 'A';
			return 1;
		}else{
			arr[i] = 'G';
			return calc(i+1, sa, sb+b[i]);
		}
	}
}
int main()
{
    int i=0;
    ip(n);
    For(i,n)
    {
    	ip(a[i]);
    	ip(b[i]);
    }
    if(calc(0,0,0))
    printf("%s",arr);
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef signed long long int lli;
#define ip(n) scanf("%d",&n)
#define For(i,n) for(i;i<n;i++)
#define INF 99999999
#define VERT 1
vector< vector<pair<int,int> > > graph = vector <vector<pair<int, int> > > (5000+1);
vector<int> visited = vector<int> (VERT+1,0), parent = vector<int> (VERT + 1);
vector<int> dist=vector<int> (VERT + 1);

void Dijkstra(int source,int n)//n is the no. of vertices;
{
    for(int i=1;i<=n;i++)// Initially setting shortest distance of each vertex from the source vertex to be infinity
        dist[i]=INT_MAX;

    dist[source]=0;

    priority_queue<pair<int,int>, vector<pair<int,int> >,std::greater<pair<int,int> > >p;
    p.push(make_pair(0,source));
 	parent[source] = -1;
    while(p.empty()==false)
    {
        pair<int,int> current = p.top();
        p.pop();
        int cv=current.second;//current vertex which has been extracted out from min heap
        int cw=current.first;//current min dist till this vertex from the source

        if(visited[cv]==1)//if the node is already visited then continue;
            continue;

        visited[cv]=1;//mark the node as visited

        for(vector<pair<int,int> >::iterator itr=graph[cv].begin();itr!=graph[cv].end();itr++)
        {
             if(visited[itr->second]==0&&dist[itr->second]>cw+itr->first)
             {
             	parent[itr->second] = cv;
             	dist[itr->second]=cw+itr->first;
            	p.push(make_pair(dist[itr->second],itr->second));
             }
        }
    }
}
 void printPath(int j)
{
    // Base Case : If j is source
    if (parent[j]==-1)
    {
    	cout<<j<<" ";
        return;
	}
    printPath(parent[j]);
    printf("%d ", j);
}

int a[1000003], b[1000003],n;
char arr[1000003];
int calc(int i, lli sa, lli sb)
{
	if(i==n && sa-sb<501)
	{
		arr[i] = '\0';
		return 1;
	}
	if(sa-sb>0)
	{
		if(b[i] + sb <= sa  + 500)
		{
			arr[i] = 'G';
			return calc(i+1, sa, sb + b[i]);
		}
		else if( sa + a[i] <= sb + 500)
		{
			arr[i] = 'A';
			return calc(i+1, sa + a[i], sb);
		}

		else
		return 0;
	}
	else if(sb-sa>0)
	{
		if(a[i] + sa <= sb  + 500)
		{
			arr[i] = 'A';
			return calc(i+1, sa + a[i], sb );
		}
		else if( sb + b[i] >= sa + 500)
		{
			arr[i] = 'G';
			return calc(i+1, sa , b[i]+ sb);
		}

		else
		return 0;
	}
	else
	{
		if(a[i]<501 && calc(i+1, sa + a[i], sb))
		{
			arr[i] = 'A';
			return 1;
		}else{
			arr[i] = 'G';
			return calc(i+1, sa, sb+b[i]);
		}
	}
}
int main()
{
    int i=0;
    ip(n);
    For(i,n)
    {
    	ip(a[i]);
    	ip(b[i]);
    }
    if(calc(0,0,0))
    printf("%s",arr);
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef signed long long int lli;
#define ip(n) scanf("%d",&n)
#define For(i,n) for(i;i<n;i++)
#define INF 99999999
#define VERT 1
vector< vector<pair<int,int> > > graph = vector <vector<pair<int, int> > > (5000+1);
vector<int> visited = vector<int> (VERT+1,0), parent = vector<int> (VERT + 1);
vector<int> dist=vector<int> (VERT + 1);

void Dijkstra(int source,int n)//n is the no. of vertices;
{
    for(int i=1;i<=n;i++)// Initially setting shortest distance of each vertex from the source vertex to be infinity
        dist[i]=INT_MAX;

    dist[source]=0;

    priority_queue<pair<int,int>, vector<pair<int,int> >,std::greater<pair<int,int> > >p;
    p.push(make_pair(0,source));
 	parent[source] = -1;
    while(p.empty()==false)
    {
        pair<int,int> current = p.top();
        p.pop();
        int cv=current.second;//current vertex which has been extracted out from min heap
        int cw=current.first;//current min dist till this vertex from the source

        if(visited[cv]==1)//if the node is already visited then continue;
            continue;

        visited[cv]=1;//mark the node as visited

        for(vector<pair<int,int> >::iterator itr=graph[cv].begin();itr!=graph[cv].end();itr++)
        {
             if(visited[itr->second]==0&&dist[itr->second]>cw+itr->first)
             {
             	parent[itr->second] = cv;
             	dist[itr->second]=cw+itr->first;
            	p.push(make_pair(dist[itr->second],itr->second));
             }
        }
    }
}
 void printPath(int j)
{
    // Base Case : If j is source
    if (parent[j]==-1)
    {
    	cout<<j<<" ";
        return;
	}
    printPath(parent[j]);
    printf("%d ", j);
}

lli a[1000003], b[1000003],n;
char arr[1000003];
int calc(int i, lli sa, lli sb)
{
	if(i==n && abs(sa-sb)<501)
	{
		arr[i] = '\0';
		return 1;
	}
	if(sa-sb>0)
	{
		if((b[i] + sb <= sa  + 500)&&calc(i+1, sa, sb + b[i]))
		{
			arr[i] = 'G';
			return 1;
		}
		else if(( sa + a[i] <= sb + 500)&&calc(i+1, sa + a[i], sb))
		{
			arr[i] = 'A';
			return 1;
		}

		else
		return 0;
	}
	else if(sb-sa>0)
	{
		if((a[i] + sa <= sb  + 500) && calc(i+1, sa + a[i], sb ))
		{
			arr[i] = 'A';
			return 1;
		}
		else if(( sb + b[i] >= sa + 500) && calc(i+1, sa , b[i]+ sb))
		{
			arr[i] = 'G';
			return 1;
		}

		else
		return 0;
	}
	else
	{
		if(a[i]<501 && calc(i+1, sa + a[i], sb))
		{
			arr[i] = 'A';
			return 1;
		}else{
			arr[i] = 'G';
			return calc(i+1, sa, sb+b[i]);
		}
	}
	return 0;
}
int main()
{
    int i=0;
    ip(n);
    For(i,n)
    {
    	ip(a[i]);
    	ip(b[i]);
    }
    if(calc(0,0,0))
    printf("%s",arr);
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef signed long long int lli;
#define ip(n) scanf("%d",&n)
#define For(i,n) for(i;i<n;i++)
#define INF 99999999
#define VERT 1
vector< vector<pair<int,int> > > graph = vector <vector<pair<int, int> > > (5000+1);
vector<int> visited = vector<int> (VERT+1,0), parent = vector<int> (VERT + 1);
vector<int> dist=vector<int> (VERT + 1);

void Dijkstra(int source,int n)//n is the no. of vertices;
{
    for(int i=1;i<=n;i++)// Initially setting shortest distance of each vertex from the source vertex to be infinity
        dist[i]=INT_MAX;

    dist[source]=0;

    priority_queue<pair<int,int>, vector<pair<int,int> >,std::greater<pair<int,int> > >p;
    p.push(make_pair(0,source));
 	parent[source] = -1;
    while(p.empty()==false)
    {
        pair<int,int> current = p.top();
        p.pop();
        int cv=current.second;//current vertex which has been extracted out from min heap
        int cw=current.first;//current min dist till this vertex from the source

        if(visited[cv]==1)//if the node is already visited then continue;
            continue;

        visited[cv]=1;//mark the node as visited

        for(vector<pair<int,int> >::iterator itr=graph[cv].begin();itr!=graph[cv].end();itr++)
        {
             if(visited[itr->second]==0&&dist[itr->second]>cw+itr->first)
             {
             	parent[itr->second] = cv;
             	dist[itr->second]=cw+itr->first;
            	p.push(make_pair(dist[itr->second],itr->second));
             }
        }
    }
}
 void printPath(int j)
{
    // Base Case : If j is source
    if (parent[j]==-1)
    {
    	cout<<j<<" ";
        return;
	}
    printPath(parent[j]);
    printf("%d ", j);
}

int a[1000003], b[1000003],n;
char arr[1000003];
int calc(int i, lli sa, lli sb)
{
	if(i==n && sa-sb<501)
	{
		arr[i] = '\0';
		return 1;
	}
	if(sa-sb>0)
	{
		if(b[i] + sb <= sa  + 500)
		{
			arr[i] = 'G';
			return calc(i+1, sa, sb + b[i]);
		}
		else if( sa + a[i] <= sb + 500)
		{
			arr[i] = 'A';
			return calc(i+1, sa + a[i], sb);
		}

		else
		return 0;
	}
	else if(sb-sa>0)
	{
		if(a[i] + sa <= sb  + 500)
		{
			arr[i] = 'A';
			return calc(i+1, sa + a[i], sb );
		}
		else if( sb + b[i] >= sa + 500)
		{
			arr[i] = 'G';
			return calc(i+1, sa , b[i]+ sb);
		}

		else
		return 0;
	}
	else
	{
		if(a[i]<501)
		{
			arr[i] = 'A';
			return calc(i+1, sa+a[i], sb);
		}else{
			arr[i] = 'G';
			return calc(i+1, sa, sb+b[i]);
		}
	}
}
int main()
{
    int i=0;
    ip(n);
    For(i,n)
    {
    	ip(a[i]);
    	ip(b[i]);
    }
    if(calc(0,0,0))
    printf("%s",arr);
    else cout<<-1;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef signed long long int lli;
#define ip(n) scanf("%d",&n)
#define For(i,n) for(i;i<n;i++)
#define INF 99999999
#define VERT 1
vector< vector<pair<int,int> > > graph = vector <vector<pair<int, int> > > (5000+1);
vector<int> visited = vector<int> (VERT+1,0), parent = vector<int> (VERT + 1);
vector<int> dist=vector<int> (VERT + 1);

void Dijkstra(int source,int n)//n is the no. of vertices;
{
    for(int i=1;i<=n;i++)// Initially setting shortest distance of each vertex from the source vertex to be infinity
        dist[i]=INT_MAX;

    dist[source]=0;

    priority_queue<pair<int,int>, vector<pair<int,int> >,std::greater<pair<int,int> > >p;
    p.push(make_pair(0,source));
 	parent[source] = -1;
    while(p.empty()==false)
    {
        pair<int,int> current = p.top();
        p.pop();
        int cv=current.second;//current vertex which has been extracted out from min heap
        int cw=current.first;//current min dist till this vertex from the source

        if(visited[cv]==1)//if the node is already visited then continue;
            continue;

        visited[cv]=1;//mark the node as visited

        for(vector<pair<int,int> >::iterator itr=graph[cv].begin();itr!=graph[cv].end();itr++)
        {
             if(visited[itr->second]==0&&dist[itr->second]>cw+itr->first)
             {
             	parent[itr->second] = cv;
             	dist[itr->second]=cw+itr->first;
            	p.push(make_pair(dist[itr->second],itr->second));
             }
        }
    }
}
 void printPath(int j)
{
    // Base Case : If j is source
    if (parent[j]==-1)
    {
    	cout<<j<<" ";
        return;
	}
    printPath(parent[j]);
    printf("%d ", j);
}

int a[1000003], b[1000003],n;
char arr[1000003];
int calc(int i, lli sa, lli sb)
{
	if(i==n && sa-sb<501)
	{
		arr[i] = '\0';
		return 1;
	}
	if(sa-sb>0)
	{
		if(b[i] + sb > sa  + 500)return 0;
		else
		{
			arr[i] = 'G';
			return calc(i+1, sa, sb + b[i]);
		}
	}
	else if(sb-sa>0)
	{
		if(a[i] + sa > sb  + 500)return 0;
		else
		{
			arr[i] = 'A';
			return calc(i+1, sa + a[i], sb );
		}
	}
	else
	{
		if(a[i]<501)
		{
			arr[i] = 'A';
			return calc(i+1, sa+a[i], sb);
		}else{
			arr[i] = 'G';
			return calc(i+1, sa, sb+b[i]);
		}
	}
}
int main()
{
    int i=0;
    ip(n);
    For(i,n)
    {
    	ip(a[i]);
    	ip(b[i]);
    }
    if(calc(0,0,0))
    printf("%s",arr);
    else cout<<-1;
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
int n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%d",&n)!=EOF)
    {
        mem(c);
        mx=mn=0;
        for(i=0;i<n;i++)
        {
            scanf("%d %d",&a[i],&b[i]);
            if(mx+a[i]<b[i]+mn)
            {
                mx+=a[i];
                c[i]='A';
            }
            else
            {
                mn+=b[i];
                c[i]='G';
            }
        }
        if(abs(mx-mn)>500)
        {
            printf("-1\n");
        }
        else
        {
            printf("%s",c);
        }
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
int n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%d",&n)!=EOF)
    {
        mem(c);
        mx=mn=0;
        for(i=0;i<n;i++)
        {
            scanf("%d %d",&a[i],&b[i]);
            if(mx+a[i]<b[i]+mn)
            {
                mx+=a[i];
                c[i]='A';
            }
            else
            {
                mn+=b[i];
                c[i]='G';
            }
        }
        if((abs(mx-mn)>500)||(abs(mn-mx)==0))
        {
            printf("-1\n");
        }
        else
        {
            printf("%s\n",c);
        }
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
LL n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%I64d",&n)!=EOF)
    {
        mem(c);
        mx=mn=0;
        for(i=0;i<n;i++)
        {
            scanf("%I64d %I64d",&a[i],&b[i]);
            if(mx+a[i]<=b[i]+mn)
            {
                mx+=a[i];
                c[i]='A';
            }
            else
            {
                mn+=b[i];
                c[i]='G';
            }
        }
        if(fabs(mx-mn)>500)
        {
            printf("-1\n");
        }
        else
        {
            printf("%s\n",c);
        }
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
int n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%d",&n)!=EOF)
    {
        mem(c);
        mx=mn=0;
        for(i=0;i<n;i++)
        {
            scanf("%d %d",&a[i],&b[i]);
            if(mx+a[i]-mn<=500)
            {
                mx+=a[i];
                c[i]='A';
            }
            else
            {
                mn+=b[i];
                c[i]='G';
            }
        }
        printf("%s\n",c);
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
int n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%d",&n)!=EOF)
    {
        mem(p);
        mem(c);
        mx=mn=0;
        for(i=0;i<n;i++)
        {
            scanf("%d %d",&a[i],&b[i]);
            if(mx+a[i]<=b[i]+mn)
            {
                mx+=a[i];
                c[i]='A';
                p[0]++;
            }
            else
            {
                mn+=b[i];
                c[i]='G';
                p[1]++;
            }
        }
        if(abs(mx-mn)>500)
        {
            printf("-1\n");
        }
        else
        {
            for(j=0;j<n;j++)
            {
                printf("%c",c[j]);
            }
            printf("\n");
        }
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
LL n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%I64d",&n)!=EOF)
    {
        mem(p);
        mem(c);
        mx=mn=0;
        for(i=0;i<n;i++)
        {
            scanf("%I64d %I64d",&a[i],&b[i]);
            if(mx+a[i]<=b[i]+mn)
            {
                mx+=a[i];
                c[i]='A';
                p[0]++;
            }
            else
            {
                mn+=b[i];
                c[i]='G';
                p[1]++;
            }
        }
        if((fabs(mx-mn)>500)||(p[0]==0)||(p[1]==0))
        {
            printf("-1\n");
        }
        else
        {
            printf("%s\n",c);
        }
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
int n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%d",&n)!=EOF)
    {
        mem(c);
        mx=mn=0;
        for(i=0;i<n;i++)
        {
            scanf("%d %d",&a[i],&b[i]);
            if(mx+a[i]<b[i]+mn)
            {
                mx+=a[i];
                c[i]='A';
            }
            else
            {
                mn+=b[i];
                c[i]='G';
            }
        }
        if(abs(mx-mn)>500)
        {
            printf("-1\n");
        }
        else
        {
            printf("%s\n",c);
        }
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
int n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%d",&n)!=EOF)
    {
        mem(c);
        mx=mn=0;
        for(i=0;i<n;i++)
        {
            scanf("%d %d",&a[i],&b[i]);
            if(mx+a[i]<=mn+b[i])
            {
                mx+=a[i];
                c[i]='A';
            }
            else
            {
                mn+=b[i];
                c[i]='G';
            }
        }
        if(abs(mx-mn)>500)
        {
            printf("-1\n");
        }
        else
        {
            printf("%s\n",c);
        }
    }
    return 0;
}


#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include<map>
#include<string>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<ctype.h>
#include<deque>
#include<list>
#include<set>
#define INF 999999999
#define NEG -999999999
#define pi acos(-1.0)
#define LL long long int
#define LU unsigned long long int
#define EPS 1e-9
#define MOD 100000007
#define mem(a) memset(a,0,sizeof(a))

using namespace std;
int n,m,i,j,k,l,a[1000009],b[1000009],p[1000009],ans,cn,t,x,y,z,mx,mn,s;
char c[1000009],d[1000009],ch;
int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    while(scanf("%d",&n)!=EOF)
    {
        mem(p);
        mem(c);
        mx=mn=0;
        for(i=0;i<n;i++)
        {
            scanf("%d %d",&a[i],&b[i]);
            if(mx+a[i]<=b[i]+mn)
            {
                mx+=a[i];
                c[i]='A';
                p[0]++;
            }
            else
            {
                mn+=b[i];
                c[i]='G';
                p[1]++;
            }
        }
        if(abs(mx-mn)>=500)
        {
            printf("-1\n");
        }
        else
        {
            printf("%s\n",c);
        }
    }
    return 0;
}


#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <assert.h>
#include <ctime>
#include <bitset>
#include <numeric>
#include <complex>
#include <valarray>
using namespace std;

#define FOREACH(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for (register int i = (a); i < (int)(n); ++i)
#define FORE(i, a, n) for (i = (a); i < (int)(n); ++i)
#define Size(n) ((int)(n).size())
#define all(n) (n).begin(), (n).end()
#define ll long long
#define pb push_back
#define error(x) cout << #x << " = " << (x) << endl;
#define ull unsigned long long
#define pii pair<int, int>
//#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define point complex<double>
#define X real()
#define Y imag()
//#define X first
//#define Y second
#define EPS 1e-10
//#define endl "\n"
#define pdd pair<double, double>
#define mk make_pair

int main() {
    int n;
    cin >> n;
    int tot = 0;
    FOR(i, 0, n) {
        int a, b;
        cin >> a >> b;
        if (tot+a <= 500) {
            tot += a;
            cout << "A";
        } else {
            tot -= b;
            cout << "G";
        }
    }
    cout << endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    int tot = 0;
    for(int i= 0;i< n;i++) {
        int a, b;
        cin >> a >> b;
        if (tot+a <= 500) {
            tot += a;
            cout << "A";
        } else {
            tot -= b;
            cout << "G";
        }
    }
    cout << endl;
    return 0;
}


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

int main() {
        int t;
        cin>>t;
        int sum=0;
        for(int i=0;i<t;i++){
            int x,y;
            cin>>x>>y;

            if(sum+x<=500)
            {
                sum=sum+x;
                cout<<"A";
            }else{
                sum=sum-y;
                cout<<"G";
            }
        }

        return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;

int main()
{
    int n, dif = 0, x, y;
    cin >> n;
    while (n--)
    {
        scanf("%d%d", &x, &y);
        if (abs(dif + x) <= abs(dif - y)) dif += x, printf("A");
        else dif -= y, printf("G");
    }
}


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

int main() {
        int t;
        cin>>t;
        int sum=0;
        for(int i=0;i<t;i++){
            int x,y;
            cin>>x>>y;

            if(sum+x<500)
            {
                sum=sum+x;
                cout<<"A";
            }else{
                sum=sum-y;
                cout<<"G";
            }
        }
        cout<<endl;
        return 0;
}


#include <bits/stdc++.h>
using namespace std;
//
int main() {
    int n;
    cin >> n;
    int tot = 0;
    for(int i= 0;i< n;i++) {
        int a, b;
        cin >> a >> b;
        if (tot+a <= 500) {
            tot += a;
            cout << "A";
        } else {
            tot -= b;
            cout << "G";
        }
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <cmath>
#include <utility>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <sstream>
using namespace std;

int main()
{
	int n, dif = 0, x, y;
	cin >> n;
	while (n--)
	{
		scanf("%d%d", &x, &y);
		if (abs(dif + x) <= abs(dif - y)) dif += x, printf("A");
		else dif -= y, printf("G");
	}
}


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

int main() {
        int t;
        cin>>t;
        int sum=0;
        for(int i=0;i<t;i++){
            int x,y;
            cin>>x>>y;

            if(sum+x<=500)
            {
                sum=sum+x;
                cout<<"A";
            }else{
                sum=sum-y;
                cout<<"G";
            }
        }
        cout<<endl;
        return 0;
}


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

int main() {
        int t;
        cin>>t;
        int sum=0;
        while(t--){
            int x,y;
            cin>>x>>y;

            if(sum+x<500)
            {
                sum=sum+x;
                cout<<"A";
            }else{
                sum=sum-y;
                cout<<"G";
            }
        }
        cout<<endl;
        return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#define maxn 1000010

char str[maxn];
using namespace std;
int main(int argc, char *argv[])
{
    int n,sa,sb,a,b,i=0;
    sa = sb = 0;
    cin>>n;
    while(n--)
    {
        cin>>a>>b;
        if(sa+a-sb<=500)
        {
            sa += a;
            str[i++] = 'A';
        }
        else
        {
            if(sb+b-sa<=500)
            {
                sb += b;
                str[i++] = 'G';
            }
            else
            {
                puts("-1");
            }
        }
    }
    puts(str);
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;

const int maxn = 1e6;

struct node
{
    int a;
    int b;
}p[maxn];

int n;
int s1,s2;
char ans[maxn];

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        s1= 0;s2 = 0;
        memset(ans,0,sizeof(ans));
        for (int i=0; i<n; i++)
        {
            scanf("%d %d",&p[i].a,&p[i].b);

        }
        int num=0;
        for (int i=0; i<n; i++)
        {
            if (abs(s1 + p[i].a - s2) < abs(s1 - (s2 + p[i].b)))
            {
                s1 +=p[i].a;
            ans[num++]='A';
            }
            else
            {
                s2 += p[i].b;
                ans[num++]='G';
            }
        }
        if (abs(s1 - s2)>500)
        {
            printf("-1\n");
            continue;
        }
        printf("%s\n",ans);
    }
    return 0;
}


#include <cmath>
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;

int x,y;
int n,a,b;

int main()
{
    while(~scanf("%d",&n))
    {
        a = 0,b = 0;
        int ans = 0;
        char num[100010];
        memset(num,0,sizeof(num));
        for (int i=0; i<n; i++)
        {
            scanf("%d %d",&x,&y);
            if (abs(a + x - b) <abs(a- b -y))
            {
                num[ans++] = 'A';
                a += x;
            }
            else
            {
                b += y;
                num[ans++] = 'G';
            }
        }
        if (abs(a-b) <=500)
        printf("%s\n",num);
        else
        printf("-1\n");
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;

const int maxn = 1e6;

struct node
{
    int a;
    int b;
}p[maxn];

int n;
int s1,s2;
char ans[maxn];

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        s1= 0;s2 = 0;
        memset(ans,0,sizeof(ans));
        for (int i=0; i<n; i++)
        {
            scanf("%d %d",&p[i].a,&p[i].b);

        }
        int num=0;
        for (int i=0; i<n; i++)
        {
            if (abs(s1 + p[i].a - s2) < abs(s1 - (s2 + p[i].b)))
            {
                s1 +=p[i].a;
            ans[num++]='A';
            }
            else
            {
                s2 += p[i].b;
                ans[num++]='G';
            }
        }
        printf("s1=%d s2 =%d\n",s1,s2);
        if (abs(s1 - s2)>500)
        {
            printf("-1\n");
            continue;
        }
        printf("%s\n",ans);
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;

const int maxn = 1e6;

struct node
{
    int a;
    int b;
}p[maxn];

int n;
int s1,s2;
char ans[maxn];

int main()
{
   // freopen("in.txt","r",stdin);
    while(scanf("%d",&n)!=EOF)
    {
        s1= 0;s2 = 0;
        memset(ans,0,sizeof(ans));
        for (int i=0; i<n; i++)
        {
            scanf("%d %d",&p[i].a,&p[i].b);

        }
        int num = 0;
        int flag = 0;
        for (int i=0; i<n; i++)
        {
            if (abs(s1+p[i].a -s2)<=500)
            {
                ans[num++]= 'A';
                s1 += p[i].a;
            }
            else
            {if (abs(s1 - s2-p[i].b) <=500)
            {
                s2 += p[i].b;
                ans[num++] = 'G';
            }
            else
            {
                printf("-1\n");
                flag = 1;
            }
            }

        }
        if (!flag)
        printf("%s\n",ans);
    }
    return 0;
}


#include <cmath>
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;

int x,y;
int n,a,b;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        a = 0,b = 0;
        int ans = 0;
        char num[1000100];
        memset(num,0,sizeof(num));
        for (int i=0; i<n; i++)
        {
            scanf("%d %d",&x,&y);
            if (abs(a + x - b) <abs(b+y-a))
            {
                num[ans++] = 'A';
                a += x;
            }
            else
            {
                b += y;
                num[ans++] = 'G';
            }
        }
        num[ans] = 0;
        if (abs(a-b) <=500)
        printf("%s\n",num);
        else
        printf("-1\n");
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;

const int maxn = 1e6;

struct node
{
    int a;
    int b;
}p[maxn];

int n;
int s1,s2;
char ans[maxn];

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        s1= 0;s2 = 0;
        memset(ans,0,sizeof(ans));
        for (int i=0; i<n; i++)
        {
            scanf("%d %d",&p[i].a,&p[i].b);

        }
        int num = 0;
        int flag = 0;
        for (int i=0; i<n; i++)
        {
            if (abs(s1+p[i].a -s2)<=500)
            {
                ans[num++]= 'A';
                s1 += p[i].a;
            }
            else if (abs(s1 - s2-p[i].b) <=500)
            {
                s2 += p[i].b;
                ans[num++] = 'G';
            }
            else
            {
                printf("-1\n");
                flag = 1;
            }
        }
        if (!flag)
        printf("%s\n",ans);
    }
    return 0;
}


#include <cmath>
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;

int x,y;
int n,a,b;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        a = 0,b = 0;
        int ans = 0;
        char num[100010];
        memset(num,0,sizeof(num));
        for (int i=0; i<n; i++)
        {
            scanf("%d %d",&x,&y);
            if (abs(a + x - b) <abs(a- b -y))
            {
                num[ans++] = 'A';
                a += x;
            }
            else
            {
                b += y;
                num[ans++] = 'G';
            }
        }
        if (abs(a-b) <=500)
        printf("%s\n",num);
        else
        printf("-1\n");
    }
    return 0;
}


#include <cmath>
#include <cstring>
#include <iostream>
#include <cstdio>
using namespace std;

int x,y;
int n,a,b;

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        a = 0,b = 0;
        int ans = 0;
        char num[100010];
        memset(num,0,sizeof(num));
        for (int i=0; i<n; i++)
        {
            scanf("%d %d",&x,&y);
            if (abs(a + x - b) <abs(b+y-a))
            {
                num[ans++] = 'A';
                a += x;
            }
            else
            {
                b += y;
                num[ans++] = 'G';
            }
        }
        num[ans] = 0;
        if (abs(a-b) <=500)
        printf("%s\n",num);
        else
        printf("-1\n");
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;

const int maxn = 1e6;

struct node
{
    int a;
    int b;
} p[maxn];

int n;
int s1,s2;
char ans[maxn];

int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        s1= 0;
        s2 = 0;
        memset(ans,0,sizeof(ans));
        for (int i=0; i<n; i++)
        {
            scanf("%d %d",&p[i].a,&p[i].b);

        }
        int num = 0;
        int flag = 0;
        for (int i=0; i<n; i++)
        {
            if (abs(s1+p[i].a -s2)<=500)
            {
                ans[num++]= 'A';
                s1 += p[i].a;
            }
            else
            {
                if (s2+p[i].b - s1 <=500)
                {
                    s2 += p[i].b;
                    ans[num++] = 'G';
                }
                else
                {
                    printf("-1\n");
                    flag = 1;
                }
            }

        }
        if (!flag)
            printf("%s\n",ans);
    }
    return 0;
}


#include<stdio.h>
#include<algorithm>

#define maxn 1001000

using namespace std;

int Dis(int a,int b)
{
    if (a < b) return b - a;
    return a - b;
}

char ans[maxn],dis[maxn];

int main()
{
    int n,i,g,q,a,k,rest;
    long long sum = 0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++)
        scanf("%d%d",&a,&g),sum += a;
    k = sum / 1000;
    rest = sum % 1000;

    if (rest <= 500) {
        for(i = 1;i <= k;i++) ans[i-1] = 'G';
        for(i = k + 1;i <= n;i++) ans[i-1] = 'A';
        ans[n] = 0;
        printf("%s",ans);
        }
    else {
        printf("-1\n");
        }
    return 0;
}


#include<stdio.h>
#include<algorithm>

#define maxn 1001000

using namespace std;

int Dis(int a,int b)
{
    if (a < b) return b - a;
    return a - b;
}

char ans[maxn],dis[maxn];

int main()
{
    int n,i,g,q,a,k,rest;
    long long sum = 0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++)
        scanf("%d%d",&a,&g),sum += a;
    k = sum / 1000;
    rest = sum % 1000;

    if (rest <= 500) {
        for(i = 1;i <= k;i++) ans[i-1] = 'G';
        for(i = k + 1;i <= n;i++) ans[i-1] = 'A';
        ans[n] = 0;
        printf("%s",ans);
        }
    else {
        for(i = 1;i <= k;i++) ans[i-1] = 'G';
        for(i = k + 1;i <= n;i++) ans[i-1] = ' A';
        ans[n] = 0;
        printf("%s",ans);
        }
    return 0;
}


#include<stdio.h>
#include<algorithm>

#define maxn 1001000

using namespace std;

int Dis(int a,int b)
{
    if (a < b) return b - a;
    return a - b;
}

char ans[maxn],dis[maxn];

int main()
{
    int n,i,g,q,a,k1,k2,rest;
    long long sum = 0,sa = 0,sg = 0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++) {
        scanf("%d%d",&a,&g);
        sa += a;
        sg += g;
        }
    k1 = sa / 1000;
    k2 = sg / 1000;
    rest = sum % 1000;

    if (rest <= 500) {
        for(i = 1;i <= k1;i++) ans[i-1] = 'G';
        for(i = k1 + 1;i <= n;i++) ans[i-1] = 'A';
        ans[n] = 0;
        printf("%s",ans);
        }
    else {
        for(i = 1;i <= k2;i++) ans[i-1] = 'G';
        for(i = k2 + 1;i <= n;i++) ans[i-1] = ' A';
        ans[n] = 0;
        printf("%s",ans);
        }
    return 0;
}


#include<stdio.h>
#include<algorithm>

#define maxn 1001000

using namespace std;

int Dis(int a,int b)
{
    if (a < b) return b - a;
    return a - b;
}

char ans[maxn],dis[maxn];

int main()
{
    int n,i,g,q,a,k1,k2,rest;
    long long sum = 0,sa = 0,sg = 0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++) {
        scanf("%d%d",&a,&g);
        sa += a;
        sg += g;
        }
    k1 = sa / 1000;
    k2 = sg / 1000;
    rest = sum % 1000;

    if (rest <= 500) {
        for(i = 1;i <= k1;i++) ans[i-1] = 'G';
        for(i = k1 + 1;i <= n;i++) ans[i-1] = 'A';
        ans[n] = 0;
        printf("%s",ans);
        }
    else {
        for(i = 1;i <= k2;i++) ans[i-1] = 'A';
        for(i = k2 + 1;i <= n;i++) ans[i-1] = 'G';
        ans[n] = 0;
        printf("%s",ans);
        }
    return 0;
}


#include<stdio.h>
#include<algorithm>

#define maxn 1001000

using namespace std;

int Dis(int a,int b)
{
    if (a < b) return b - a;
    return a - b;
}

char ans[maxn],dis[maxn];

int main()
{
    int n,i,g,q,a,k,rest,sum = 0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++)
        scanf("%d%d",&a,&g),sum += a;
    k = sum / 1000;
    rest = sum % 1000;

    if (rest <= 500) {
        for(i = 1;i <= k;i++) ans[i-1] = 'G';
        for(i;i <= n;i++) ans[i-1] = 'A';
        ans[n] = 0;
        printf("%s",ans);
        }
    else {
        for(i = 1;i <= k;i++) ans[i-1] = 'A';
        for(i;i <= n;i++) ans[i-1] = 'G';
        ans[n] = 0;
        printf("%s",ans);
        }
    return 0;
}


#include<stdio.h>
#include<algorithm>

#define maxn 1001000

using namespace std;

char ans[maxn];

int main()
{
    int n,i,g,q,a,k1,k2,rest;
    long long sum = 0,sa = 0,sg = 0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++) {
        scanf("%d%d",&a,&g);
        sa += a;
        sg += g;
        }
    k1 = sa / 1000;
    k2 = sg / 1000;
    rest = sa % 1000;

    if (rest <= 500) {
        for(i = 1;i <= k1;i++) ans[i-1] = 'G';
        for(i = k1 + 1;i <= n;i++) ans[i-1] = 'A';
        ans[n] = 0;
        printf("%s",ans);
        }
    else {
        for(i = 1;i <= k2;i++) ans[i-1] = 'A';
        for(i = k2 + 1;i <= n;i++) ans[i-1] = 'G';
        ans[n] = 0;
        printf("%s",ans);
        }
    return 0;
}


#include<stdio.h>
#include<algorithm>

#define maxn 1001000

using namespace std;

int Dis(int a,int b)
{
    if (a < b) return b - a;
    return a - b;
}

char ans[maxn],dis[maxn];

int main()
{
    int n,i,g,q,a,k,rest;
    long long sum = 0;
    scanf("%d",&n);
    for(i = 1;i <= n;i++)
        scanf("%d%d",&a,&g),sum += a;
    k = sum / 1000;
    rest = sum % 1000;

    if (rest <= 500) {
        for(i = 1;i <= k;i++) ans[i-1] = 'G';
        for(i = k + 1;i <= n;i++) ans[i-1] = 'A';
        ans[n] = 0;
        printf("%s",ans);
        }
    else {
        for(i = 1;i <= k;i++) ans[i-1] = 'A';
        for(i = k + 1;i <= n;i++) ans[i-1] = 'G';
        ans[n] = 0;
        printf("%s",ans);
        }
    return 0;
}


#include<stdio.h>
#include<algorithm>

#define maxn 1001000

using namespace std;

struct Node{
    int val,pos;
    } dis[maxn];

int cmp(Node a,Node b)
{
    return a.val < b.val;
}

int Dis(int a,int b)
{
    if (a < b) return b - a;
    return a - b;
}

char ans[maxn];

int main()
{
    int n,i,g,q,a;
    scanf("%d",&n);
    for(i = 1;i <= n;i++) {
        scanf("%d%d",&a,&g);
        dis[i].pos = i;
        dis[i].val = Dis(g,a);
        }
    sort(dis+1,dis+n+1,cmp);
    int xx = 0;
    for(i = 1;i <= n;i++) {
        if (i & 1) ans[dis[i].pos-1] = 'A';
        else ans[dis[i].pos-1] = 'G';
        if (i & 1) xx += dis[i].val;
        else xx -= dis[i].val;
        }
    ans[n] = 0;
    if (xx > 500 || xx < -500) printf("-1\n");
    else printf("%s\n",ans);
    return 0;
}


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

#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define IFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define FORD(i, a, b, c) for(int i=(a); i<(b); i+=(c))

#define SS ({int x;scanf("%d", &x);x;})
#define SI(x) ((int)x.size())
#define PB(x) push_back(x)
#define MP(a,b) make_pair(a, b)
#define SORT(a) sort(a.begin(),a.end())
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it!=a.end(); it++)
#define ALL(a) a.begin(),a.end()
#define INF 1000000000
#define V vector
#define S string
#define FST first
#define SEC second
typedef V<int> VI;
typedef V<S> VS;
typedef long long LL;
typedef pair<int, int> PII;
int main()
 {
   int n;
   cin>>n;
   int a,b,k=0;
   string s="";
   for(int i=0;i<n;i++)
    {
        cin>>a>>b;
        if(k+a<=500)
         {k=k+a;s=s+'A';}
        else
         {k=k-b;s=s+'G';}
    }
    cout<<s<<endl;
 }


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

#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define IFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define FORD(i, a, b, c) for(int i=(a); i<(b); i+=(c))

#define SS ({int x;scanf("%d", &x);x;})
#define SI(x) ((int)x.size())
#define PB(x) push_back(x)
#define MP(a,b) make_pair(a, b)
#define SORT(a) sort(a.begin(),a.end())
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it!=a.end(); it++)
#define ALL(a) a.begin(),a.end()
#define INF 1000000000
#define V vector
#define S string
#define FST first
#define SEC second
typedef V<int> VI;
typedef V<S> VS;
typedef long long LL;
typedef pair<int, int> PII;
int main()
 {
    LL n,k,k1,s=0,z=0;
    string s1="";
    cin>>n;
    for(LL i=0;i<n;i++)
     {
        cin>>k>>k1;
        if(abs((s+k))<=500)
         {
            s=s+k;
            s1=s1+'A';
         }
        else if(abs((s-k1))<=500)
         {
            s=s-k1;
            s1=s1+'G';
         }
        else
         {
            z=1;
         }
     }
    if(z==1)
     cout<<"-1"<<endl;
    else
     cout<<s1<<endl;
 }


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

#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define IFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define FORD(i, a, b, c) for(int i=(a); i<(b); i+=(c))

#define SS ({int x;scanf("%d", &x);x;})
#define SI(x) ((int)x.size())
#define PB(x) push_back(x)
#define MP(a,b) make_pair(a, b)
#define SORT(a) sort(a.begin(),a.end())
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it!=a.end(); it++)
#define ALL(a) a.begin(),a.end()
#define INF 1000000000
#define V vector
#define S string
#define FST first
#define SEC second
typedef V<int> VI;
typedef V<S> VS;
typedef long long LL;
typedef pair<int, int> PII;
int main()
 {
    LL n,k,k1,s=0,z=0;
    string s1="";
    scanf("%lld",&n);
    for(LL i=0;i<n;i++)
     {
        scanf("%lld%lld",&k,&k1);
        if(s+k<=500)
         {
            s=s+k;
            s1=s1+'A';
         }
        else if(s-k1<=500)
         {
            s=s-k1;
            s1=s1+'G';
         }
        else
         {
            z=1;
         }
     }
    if(z==1)
     cout<<"-1"<<endl;
    else
     cout<<s1<<endl;
 }


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

#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define IFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define FORD(i, a, b, c) for(int i=(a); i<(b); i+=(c))

#define SS ({int x;scanf("%d", &x);x;})
#define SI(x) ((int)x.size())
#define PB(x) push_back(x)
#define MP(a,b) make_pair(a, b)
#define SORT(a) sort(a.begin(),a.end())
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it!=a.end(); it++)
#define ALL(a) a.begin(),a.end()
#define INF 1000000000
#define V vector
#define S string
#define FST first
#define SEC second
typedef V<int> VI;
typedef V<S> VS;
typedef long long LL;
typedef pair<int, int> PII;
int main()
 {
    int n,k,k1,s=0,z=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
     {
        scanf("%d%d",&k,&k1);
        if(s+k<=500)
         {
            s=s+k;
            printf("A");
         }
        else if(s-k1<=500)
         {
            s=s-k1;
            printf("G");
         }
     }
     printf("\n");
 }


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

#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define IFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define FORD(i, a, b, c) for(int i=(a); i<(b); i+=(c))

#define SS ({int x;scanf("%d", &x);x;})
#define SI(x) ((int)x.size())
#define PB(x) push_back(x)
#define MP(a,b) make_pair(a, b)
#define SORT(a) sort(a.begin(),a.end())
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it!=a.end(); it++)
#define ALL(a) a.begin(),a.end()
#define INF 1000000000
#define V vector
#define S string
#define FST first
#define SEC second
typedef V<int> VI;
typedef V<S> VS;
typedef long long LL;
typedef pair<int, int> PII;
int main()
 {
    LL n,k,k1,s=0,z=0;
    string s1="";
    cin>>n;
    for(LL i=0;i<n;i++)
     {
        cin>>k>>k1;
        if(s+k<=500)
         {
            s=s+k;
            s1=s1+'A';
         }
        else if(s-k1<=500)
         {
            s=s-k1;
            s1=s1+'G';
         }
        else
         {
            z=1;
         }
     }
    if(z==1)
     cout<<"-1"<<endl;
    else
     cout<<s1<<endl;
 }


#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <cmath>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <assert.h>
#include <ctime>
#include <bitset>
#include <numeric>
#include <complex>
#include <valarray>
using namespace std;

#define FOREACH(i, c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define FOR(i, a, n) for (register int i = (a); i < (int)(n); ++i)
#define FORE(i, a, n) for (i = (a); i < (int)(n); ++i)
#define Size(n) ((int)(n).size())
#define all(n) (n).begin(), (n).end()
#define ll long long
#define pb push_back
#define error(x) cout << #x << " = " << (x) << endl;
#define ull unsigned long long
#define pii pair<int, int>
//#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define point complex<double>
#define X real()
#define Y imag()
//#define X first
//#define Y second
#define EPS 1e-10
//#define endl "\n"
#define pdd pair<double, double>
#define mk make_pair

int main() {
    int n;
    cin >> n;
    int tot = 0;
    FOR(i, 0, n) {
        int a, b;
        cin >> a >> b;
        if (tot+a <= 500) {
            tot += a;
            cout << "A";
        } else {
            tot -= b;
            cout << "G";
        }
    }
    cout << endl;
    return 0;
}


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

#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define IFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define FORD(i, a, b, c) for(int i=(a); i<(b); i+=(c))

#define SS ({int x;scanf("%d", &x);x;})
#define SI(x) ((int)x.size())
#define PB(x) push_back(x)
#define MP(a,b) make_pair(a, b)
#define SORT(a) sort(a.begin(),a.end())
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it!=a.end(); it++)
#define ALL(a) a.begin(),a.end()
#define INF 1000000000
#define V vector
#define S string
#define FST first
#define SEC second
typedef V<int> VI;
typedef V<S> VS;
typedef long long LL;
typedef pair<int, int> PII;
int main()
 {
   LL n;
   cin>>n;
   LL a,b,k=0;
   string s="";
   for(LL i=0;i<n;i++)
    {
        cin>>a>>b;
        if(k+a<=500)
         {k=k+a;s=s+'A';}
        else
         {k=k-b;s=s+'G';}
    }
    cout<<s<<endl;
 }


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

#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define IFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define FORD(i, a, b, c) for(int i=(a); i<(b); i+=(c))

#define SS ({int x;scanf("%d", &x);x;})
#define SI(x) ((int)x.size())
#define PB(x) push_back(x)
#define MP(a,b) make_pair(a, b)
#define SORT(a) sort(a.begin(),a.end())
#define ITER(it,a) for(typeof(a.begin()) it = a.begin(); it!=a.end(); it++)
#define ALL(a) a.begin(),a.end()
#define INF 1000000000
#define V vector
#define S string
#define FST first
#define SEC second
typedef V<int> VI;
typedef V<S> VS;
typedef long long LL;
typedef pair<int, int> PII;
int main()
 {
    int n,k,k1,s=0;
    cin>>n;
    for(int i=0;i<n;i++)
     {
        cin>>k>>k1;
        if(s+k<=500)
         {
            s=s+k;
            cout<<'A';
         }
        else
         {
            s=s-k1;
            cout<<'G';
         }
     }
 }


#include<iostream>
#include<math.h>

#include<algorithm>

using namespace std;
int main()
{
     long long n,a[1000009],b[1000006];
     cin>>n;
     for(int i =1;i<=n;i++)
     {
        cin>>a[i]>>b[i];
        if(a[i]<=500) cout<<"A";
        else          cout<<"G";
     }
return 0;

}


#include<iostream>
#include<math.h>

#include<algorithm>
long long s1=0,s2=0,n,a[1000009],b[1000006];
using namespace std;
int main()
{

     cin>>n;
     for(int i =1;i<=n;i++)
     {
        cin>>a[i]>>b[i];

        if(s1+a[i]- s2 <500) {cout<<"A"; s1+=a[i];}
        else               {cout<<"B"; s2+=b[i];}

     }
return 0;

}


#include<iostream>
#include<math.h>

#include<algorithm>
long long s1=0,s2=0,n,a[1000009],b[1000006];
using namespace std;
int main()
{

     cin>>n;
     for(int i =1;i<=n;i++)
     {
        cin>>a[i]>>b[i];

        if(s1+a[i]- s2 <500) {cout<<"A"; s1+=a[i];}
        else               {cout<<"G"; s2+=b[i];}

     }
return 0;

}


#include<iostream>
#include<math.h>

#include<algorithm>
long long s1,s2,n,a[1000009],b[1000006];
using namespace std;
int main()
{

     cin>>n;
     for(long long i =1;i<=n;i++)
     {
        cin>>a[i]>>b[i];

     }
     for(long long i =1;i<=n;i++)
     {
       if(abs(s1+a[i]- s2 )<=500) {cout<<"A"; s1+=a[i];}
        else               {cout<<"G"; s2+=b[i];}
      }
return 0;

}


#include<iostream>
#include<math.h>

#include<algorithm>
long long s1=0,s2=0,n,a[1000009],b[1000006];
using namespace std;
int main()
{

     cin>>n;
     for(int i =1;i<=n;i++)
     {
        cin>>a[i]>>b[i];

        if(s1+a[i]- s2 <=500) {cout<<"A"; s1+=a[i];}
        else               {cout<<"G"; s2+=b[i];}

     }
return 0;

}


#include<iostream>
#include<math.h>

#include<algorithm>
long long s1=0,s2=0,n,a[1000009],b[1000006];
using namespace std;
int main()
{

     cin>>n;
     for(int i =1;i<=n;i++)
     {
        cin>>a[i]>>b[i];

        if(s1+a[i]- s2 <=500) {cout<<"A"; s1+=a[i];}
        else               {cout<<"B"; s2+=b[i];}

     }
return 0;

}


#include<iostream>
#include<stdio.h>

#include<algorithm>
long long s1,s2,n,a,b;
using namespace std;
int main()
{

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

        scanf("%ld%ld",&a,&b);
        if(s1+a- s2 <500) {printf("A"); s1+=a;}
        else               {printf("G"); s2+=b;}

     }
return 0;

}


#include<iostream>
#include<math.h>

#include<algorithm>
long long s1=0,s2=0,n,a,b;
using namespace std;
int main()
{

     cin>>n;
     for(int i =1;i<=n;i++)
     {
        cin>>a>>b;

        if(s1+a- s2 <500) {cout<<"A"; s1+=a;}
        else               {cout<<"G"; s2+=b;}

     }
return 0;

}


#include<iostream>
#include<math.h>

#include<algorithm>
long long s1=0,s2=0,n,a[1000009],b[1000006];
using namespace std;
int main()
{

     cin>>n;
     for(int i =1;i<=n;i++)
     {
        cin>>a[i]>>b[i];

     }
     for(int i =1;i<=n;i++)
     {
       if(abs(s1+a[i]- s2 )<=500) {cout<<"A"; s1+=a[i];}
        else               {cout<<"G"; s2+=b[i];}
      }
return 0;

}


#include<stdio.h>
    char s[1000001];
int main()
{
    long long int n,i,f=0,sa=0,sg=0,a,g;
    scanf("%I64d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%I64d%I64d",&a,&g);
        if(sa+a>sg+g)
        {
            sg+=g;
            s[i]='G';
        }
        else
        {
            sa+=a;
            s[i]='A';
        }
    }
    s[i]='\0';
    if(sa-sg>500)
    printf("-1\n");
    else
    printf("%s\n",s);
    return 0;
}


#include<stdio.h>
int main()
{
    int n,i,f=0,sa=0,sg=0,a,g;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d%d",&a,&g);
        if(sa+a-sg>500)
        {
            sg+=g;
            putchar('G');
        }
            else
            {
                sa+=a;
                putchar('A');
            }

    }
    return 0;
}


from sys import stdin, stdout

t = int(stdin.readline())

for i in range(t):
    n, k = map(int, stdin.readline().split())
    values = sorted(list(map(int, stdin.readline().split())))
    length = [values[0], n - values[-1] + 1]

    for i in range(1, k - 1):
        cnt = values[i + 1] - values[i] + 1

        if cnt & 1:
            length.append((cnt >> 1) + 1)
        else:
            length.append(cnt >> 1)

    stdout.write(str(max(length)) + '\n')


from sys import stdin, stdout

t = int(stdin.readline())

for i in range(t):
    n, k = map(int, stdin.readline().split())
    values = sorted(list(map(int, stdin.readline().split())))
    length = [values[0], n - values[-1] + 1]

    for i in range(0, k - 1):
        cnt = values[i + 1] - values[i] + 1

        if cnt & 1:
            length.append((cnt >> 1) + 1)
        else:
            length.append(cnt >> 1)

    stdout.write(str(max(length)) + '\n')


t = int(input())
for o in range(t):
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    ans = a[0]
    for i in range(1, k):
        ans = max(ans, (a[i] - a[i - 1])//2)
    ans = max(ans, n - a[k - 1] + 1)
    print(ans)


t = int(input())
for o in range(t):
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    ans = a[0]
    for i in range(1, k):
        ans = max(ans, (a[i] - a[i - 1] + 2)//2)
    ans = max(ans, n - a[k - 1] + 1)
    print(ans)


#! /usr/bin/python3

t = int(input())

for tt in range(t):
	n,k = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a[0], n+1-a[k-1])
	for i in range(1,k-1):
		m = max(m, (a[i]-a[i-1])//2+1)
	print(m)


#! /usr/bin/python3

t = int(input())

for tt in range(t):
	n,k = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a[0], n+1-a[k-1])
	for i in range(2,k):
		m = max(m, (a[i]-a[i-1]+1)//2)
	print(m)


#! /usr/bin/python3

t = int(input())

for tt in range(t):
	n,k = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a[0], n+1-a[k-1])
	for i in range(1,k):
		m = max(m, (a[i]-a[i-1])//2+1)
	print(m)


#! /usr/bin/python3

t = int(input())

for tt in range(t):
	n,k = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a[0], n+1-a[k-1])
	for i in range(2,k):
		m = max(m, (a[i]-a[i-1]//2+1)
	print(m)


#! /usr/bin/python3

t = int(input())

for tt in range(t):
	n,k = map(int, input().split())
	a = list(map(int, input().split()))
	m = max(a[0], n+1-a[k-1])
	for i in range(2,k):
		m = max(m, (a[i]-a[i-1])//2+1)
	print(m)


for i in range(int(input())):
    n, k = [int(x) for x in input().split()]
    valves = [int(x) for x in input().split()]
    gr = [False] * n
    for i in valves:
        gr[i - 1] = True
    time = 1
    while gr.count(True) != n:
        for i in valves:
            if i - 1 - time >= 0:
                gr[i - 1 - time] = True
            if i - 1 + time < n:
                gr[i - 1 + time] = True
        time += 1
    print(time)


t=int(input())

for e in range(t):
    n,k=map(int,input().split())
    taps=list(map(int,input().split()))

    time=taps[0]

    for i in range(k-1):
        time=max(time,(taps[i+1]-taps[i])//2)
    time=max(time,n+1-taps[-1])
    print(time)


t=int(input())

for e in range(t):
    n,k=map(int,input().split())
    taps=list(map(int,input().split()))

    time=taps[0]

    for i in range(k-1):
        time=max(time,1+(taps[i+1]-taps[i])//2)
    time=max(time,n-taps[-1]+1)
    print(time)


n = int(input())
def time(str1,str2):
  x = str1[0]
  m = [1]*x
  l = 0
  while(1):
    for k in range(len(str2)):
      if str2[k] - l - 1 >= 0:
        m[str2[k] - l -1] = 0
      if str2[k] + l - 1 <= x-1 :
        m[str2[k] + l -1] = 0
    l+=1
    if sum(m) == 0:
      return(l)
      break
for i in range(n):
  arr =list(map(int,input().split(' ')))
  arr1 =list(map(int,input().split(' ')))
  result = time(arr,arr1)
  print(result)


def my_main():
    test_count = int(input())
    test_cases = []
    for i in range(test_count):
        sample=[]
        sample.append(input())
        sample.append(input())
        test_cases.append(sample)
    for i in test_cases:
        garden_bed = i[0].split()[0]
        tap_count = i[0].split()[1]
        tap_list = i[1].split()
        maximum=0
        if len(tap_list) == 1:
            maximum = int(tap_list[0]) if int(tap_list[0]) > int(garden_bed)+1 - int(tap_list[0]) else int(garden_bed)+1 - int(tap_list[0])
        else:
            for i in range(1,len(tap_list)):
                if (int(tap_list[i])-int(tap_list[i-1]))//2 +1 > maximum:
                    maximum = (int(tap_list[i])-int(tap_list[i-1]))//2 +1
            if int(garden_bed)+1 - int(tap_list[-1]) > maximum:
                maximum = int(garden_bed)+1 - int(tap_list[-1])
            if int(tap_list[0]) > maximum:
                maximum = int(tap_list[0])
        print(maximum)

if __name__ == "__main__":
    my_main()


def my_main():
    test_count = int(input())
    test_cases = []
    for i in range(test_count):
        sample=[]
        sample.append(input())
        sample.append(input())
        test_cases.append(sample)
    for i in test_cases:
        garden_bed = i[0].split()[0]
        tap_count = i[0].split()[1]
        tap_list = i[1].split()
        maximum=0
        if len(tap_list) == 1:
            maximum = int(tap_list[0]) - 1 if int(tap_list[0]) - 1 > int(garden_bed) - int(tap_list[0]) else int(garden_bed) - int(tap_list[0])
        else:
            for i in range(1,len(tap_count)):
                if (int(tap_list[i])-int(tap_list[i-1]))//2 > maximum:
                    maximum = int(tap_list[i])-int(tap_list[i-1])
            if int(garden_bed) - int(tap_list[-1]) > maximum:
                maximum = int(garden_bed) - int(tap_list[-1])
            if int(tap_list[0]) - 1 > maximum:
                maximum = int(tap_list[0]) - 1
        print(maximum+1)

if __name__ == "__main__":
    my_main()


#Poliv
t=int(input())
ans=[]
for i in range(t):
    n,k=map(int,input().split())
    kran=list(map(int,input().split()))
    kran.append(1)
    kran.append(n)
    kran.sort()
    dist=[]
    dist.append(kran[1]-kran[0]+1)
    dist.append(kran[k+1]-kran[k]+1)
    for i in range(2,k+1):
        dist.append(((kran[i]-kran[i+1])//2)+1)
    dist.sort(reverse=1)
    ans.append(dist[0])
for i in ans:
    print(i)


#Poliv
t=int(input())
ans=[]
for i in range(t):
    n,k=map(int,input().split())
    kran=list(map(int,input().split()))
    kran.append(1)
    kran.append(n)
    kran.sort()
    dist=[]
    dist.append(kran[1]-kran[0]+1)
    dist.append(kran[k+1]-kran[k]+1)
    for i in range(2,k+1):
        dist.append(((kran[i]-kran[i-1])//2)+1)
    dist.sort(reverse=1)
    ans.append(dist[0])

for i in ans:
    print(i)


t = int(input())

for _ in range(t):
    n, k = map(int, input().split())
    w = list(map(int, input().split()))

    lst1 = [w[0], n - w[-1] + 1]
    lst2 = [(w[i + 1] - w[i]) // 2 + 1 for i in range(k - 1)]

    print(max(lst1 + lst2))


import math
t = int(input())
for i in range(t):
    n, k = input().split(" ")
    n = int(n)
    k = int(k)
    arr = input().split(" ")
    if n == k:
        print(1, '\n')
        continue
    for j in range(len(arr)):
        arr[j] = int(arr[j])
    maxi = 0
    for j in range(1, k):
        if arr[j] - arr[j - 1] - 1 > maxi:
            maxi = arr[j] - arr[j - 1] - 1
    maxi = math.ceil(maxi / 2.0)
    if arr[0] > maxi:
        maxi = arr[0]
    if n - arr[len(arr) - 1] + 1 > maxi:
        maxi = n - arr[len(arr) - 1] + 1
    print(maxi, '\n')


import math
t = int(input())
for i in range(t):
    n, k = input().split(" ")
    n = int(n)
    k = int(k)
    arr = input().split(" ")
    if n == k:
        print(1, '\n')
        continue
    for j in range(len(arr)):
        arr[j] = int(arr[j])
    maxi = 0
    for j in range(1, k):
        if arr[j] - arr[j - 1] - 1 > maxi:
            maxi = arr[j] - arr[j - 1] - 1
    maxi = math.ceil(maxi / 2.0) + 1
    if arr[0] > maxi:
        maxi = arr[0]
    if n - arr[len(arr) - 1] + 1 > maxi:
        maxi = n - arr[len(arr) - 1] + 1
    print(maxi)


t = int(input())

ans = list()
for i in range(t):
    n, k = map(int, input().split())
    x = list(map(int, input().split()))

    m = x[0]
    for i, el in enumerate(x[1:]):
        m = max(m, ((el - x[i]) // 2) + 1)
    m = max(m, n - x[-1] + 1)

    ans.append(m)

print('\n'.join(map(str, ans)))


t = int(input())

while(t > 0):
    n,k = map(int, input().split())
    a=[]
    a = list(map(int, input().split()))
    l=1
    r=n
    res=1
    for i in range(k):
        res = max(res, (a[i]-l)//2+1)
        l = a[i]

    res = max(res,n-a[k-1]+1)
    print(res)

    t-=1


t = int(input())

while(t > 0):
    n,k = map(int, input().split())
    a=[]
    a = list(map(int, input().split()))
    l=1
    r=n
    res=1
    for i in range(k):
        res = max(res, (a[i]-l)//2+1)
        l = a[i]

    res = max(res, a[0]-1+1)
    res = max(res,n-a[k-1]+1)
    print(res)

    t-=1


for i in range(int(input())):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    m=0
    for i in range(1,len(a)-1):
        m=max(m,a[i]-a[i-1])
    m=max((m+1)//2,a[0],n-a[-1]+1)
    print(m)


for i in range(int(input())):
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    m=0
    for i in range(1,len(a)):
        m=max(m,a[i]-a[i-1])
    #print(m)
    m=max(m//2+1,a[0],n-a[-1]+1)
    print(m)


t = int(input())
for i in range(t):
    arr = list(int(x) for x in input().split(' '))
    n = arr[0]
    k = arr[1]
    a = list(int(x)-1 for x in input().split(' '))
    ans = list(5000 for _ in range(n))
    for x in a:
        count = 1
        for j in range(x, n, 1):
            ans[j] = min(count, ans[j])
            count += 1
        count = 1
        for j in range(x, -1, -1):
            ans[j] = min(count, ans[j])
            count += 1
    res = max(ans)
    print(res)


import math
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    taps=[]
    l=list(map(int,input().split()))
    taps.append(l[0])
    x=l[0]
    for y in l[1:]:
        taps.append(math.ceil((y-x)/2))
        x=y
    taps.append(n-x+1)
    print(max(taps))


import math
t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    taps=[]
    l=list(map(int,input().split()))
    taps.append(l[0])
    x=l[0]
    for y in l[1:]:
        taps.append(math.ceil((y-(x-1))/2))
        x=y
    taps.append(n-x+1)
    print(max(taps))


t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    taps=[]
    l=list(map(int,input().split()))
    taps.append(l[0])
    x=l[0]
    for y in l[1:]:
        taps.append((y-x)/2)
        x=y
    taps.append(n-x+1)
    print(max(taps))


t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    taps=[]
    l=map(int,input().split())
    x=0
    for y in l:
        taps.append(y-x)
        x=y
    taps.append(n-x+1)
    print(max(taps))


t=int(input())
for i in range(t):
    n,k=map(int,input().split())
    taps=[]
    l=list(map(int,input().split()))
    taps.append(l[0])
    x=l[0]
    for y in l[1:]:
        taps.append((y-x)//2)
        x=y
    taps.append(n-x+1)
    print(max(taps))


t = int(input())

for x in range(t):
    (n, k) = map(int, input().split())
    lst = []
    for y in input().split():
        lst.append(int(y))
    l = max(lst[0], n + 1 - lst[-1])
    for y in range(1, len(lst)):
        l = max(l, (lst[y] - lst[y - 1] - 1) // 2 + 1)
    print(l)


t = int(input())

for x in range(t):
    (n, k) = map(int, input().split())
    lst = []
    for y in input().split():
        lst.append(int(y))
    l = max(lst[0], n + 1 - lst[-1])
    for y in range(1, len(lst)):
        l = max(l, (lst[y] - lst[y - 1] + 2) // 2)
    print(l)


t = int(input())

for x in range(t):
    (n, k) = map(int, input().split())
    lst = []
    for y in input().split():
        lst.append(int(y))
    l = max(lst[0], n + 1 - lst[-1])
    for y in range(1, len(lst)):
        l = max(l, (lst[y] - lst[y - 1]) // 2)
    print(l)


t = int(input())

for test in range(t):
    n, k = map(int, input().split())
    x = [False for i in range(n)]

    for xi in map(int, input().split()):
        x[xi-1] = True
        n = n - 1

    time = 1
    while n > 0:

        x2 = x.copy()
        for i in range(len(x)):
            if x[i] is True:
                if i > 0 and x2[i-1] is False:
                    x2[i-1] = True
                    n = n - 1
                if i + 1 < len(x) and x2[i+1] is False:
                    x2[i+1] = True
                    n = n - 1
        x = x2.copy()
        time = time + 1

    print(time)


t = int(input())

for test in range(t):
    n, k = map(int, input().split())
    x = [False for i in range(n)]

    for xi in map(int, input().split()):
        x[xi-1] = True
        n = n - 1

    time = 1
    while n > 0:

        x2 = x.copy()
        for i in range(len(x)):
            if x[i] is True:
                if i > 0 and x[i-1] is False:
                    x2[i-1] = True
                    n = n - 1
                if i + 1 < len(x) and x[i+1] is False:
                    x2[i+1] = True
                    n = n - 1
        x = x2.copy()
        time = time + 1

    print(time)


tc = int(input())
 while tc>0:
     B,T = map(int, input().split())
     A = list(map(int, input().split()))
     sec = max(A[0], B+1-A[-1])

     for i in range(1,m):
         sec = max(sec,(A[i]-A[i-1]+2)//2)
    print(sec)
    tc -=1


tc = int(input())
while tc > 0:
    B, T = map(int, input().split())
    A = list(map(int, input().split()))
    sec = max(A[0], B + 1 - A[-1])

    for i in range(1, T):
        sec = max(sec, (A[i] - A[i - 1] + 2) // 2)
    print(sec)
    tc -= 1


def solve(field, segments):
    i = 1
    while True:
        for s in segments:
            field[s[0]] = field[s[1]] = 1
            if s[0] > 0:
                s[0] -= 1
            if s[1] < len(field) - 1:
                s[1] += 1
        if sum(field) == len(field):
            print(i)
            return
        i += 1

tests = int(input())
while tests:
    tests -= 1
    n, k = map(int, input().split())
    f = [0 for _ in range(n)]
    treaps = list(map(int, input().split()))
    seg = []
    for c in treaps:
        seg.append([c - 1, c - 1])
    solve(f, seg)


def solve(field):
    changed = False
    for i in range(2, 1000):
        j = 0
        while j < len(field):
            if j > 0:
                if field[j - 1] == 1 and field[j] == 0:
                    field[j] = 1
                    j += 2
                    changed = True
            if j < len(field) - 1:
                if field[j + 1] == 1 and field[j] == 0:
                    field[j] = 1
                    changed = True
            j += 1
        if not changed:
            print(i - 1)
            return
        else:
            changed = False

tests = int(input())
while tests:
    tests -= 1
    n, k = map(int, input().split())
    f = [0 for _ in range(n)]
    treaps = list(map(int, input().split()))
    for c in treaps:
        f[c - 1] = 1
    solve(f)


n = int(input())
#n, m = map(int, input().split())
#s = input()
#c = list(map(int, input().split()))
for i in range(n):
    k, m = map(int, input().split())
    c = list(map(int, input().split()))
    l = max(k - c[-1] + 1, c[0])
    for j in range(m - 1):
        l = max(l, (c[j + 1] - c[j]) // 2 + 1)
    print(l)


import math
t = int(input())
for i in range(t):
    n, k = map(int, input().split())
    x = list(map(int, input().split()))
    mx = max(x[0], n - x[-1] + 1)
    for i in range(1, k):
        mx = max(math.floor((x[i] - x[i - 1]) / 2) + 1, mx)
    print(mx)


from collections import defaultdict
import numpy as np
import math
from sys import stdin

casenumber = int(stdin.readline())
mydict=defaultdict(list)
output=[]
for n in range(casenumber):
    string1 =  stdin.readline().strip().split()
    beds=int(string1[0])
    taps=int(string1[1])
    mydict[n+1].append(beds)
    mydict[n+1].append(taps)
    string2 =  stdin.readline().strip().split()
    for i in range(taps):
        mydict[n+1].append(int(string2[i]))
for i in range(0,casenumber):
    maxvalue=0
    for j in range(mydict[i+1][0]):
        minvalue=200
        for k in range(mydict[i+1][1]):
            d=abs((j+1)-mydict[i+1][k+2])
            if (d<minvalue):
                minvalue=d
        if (minvalue>maxvalue):
            maxvalue=minvalue
    output.append(maxvalue+1)
for i in range(casenumber):
    print (output[i])


from collections import defaultdict
import numpy as np
import math
from sys import stdin

casenumber = int(stdin.readline())
mydict=defaultdict(list)
output=[]
for n in range(casenumber):
    string1 =  stdin.readline().strip().split()
    beds=int(string1[0])
    taps=int(string1[1])
    mydict[n+1].append(beds)
    mydict[n+1].append(taps)
    string2 =  stdin.readline().strip().split()
    for i in range(taps):
        mydict[n+1].append(int(string2[i]))
for i in range(0,casenumber):
    maxvalue=0
    for j in range(mydict[i+1][0]):
        minvalue=200
        for k in range(mydict[i+1][1]):
            d=abs((j+1)-mydict[i+1][k+2])
            print("number",i+1,"bed",j+1,"value",d)
            if (d<minvalue):
                minvalue=d
        if (minvalue>maxvalue):
            maxvalue=minvalue
    output.append(maxvalue+1)

print (output)


from collections import defaultdict
import math
from sys import stdin

casenumber = int(stdin.readline())
mydict=defaultdict(list)
output=[]
for n in range(casenumber):
    string1 =  stdin.readline().strip().split()
    beds=int(string1[0])
    taps=int(string1[1])
    mydict[n+1].append(beds)
    mydict[n+1].append(taps)
    string2 =  stdin.readline().strip().split()
    for i in range(taps):
        mydict[n+1].append(int(string2[i]))
for i in range(0,casenumber):
    maxvalue=0
    for j in range(mydict[i+1][0]):
        minvalue=200
        for k in range(mydict[i+1][1]):
            d=abs((j+1)-mydict[i+1][k+2])
            if (d<minvalue):
                minvalue=d
        if (minvalue>maxvalue):
            maxvalue=minvalue
    output.append(maxvalue+1)
for i in range(casenumber):
    print (output[i])


from bisect import *

for t in range(int(input())):
    n, k = map(int, input().split())

    K = list(map(int, input().split()))
    K.sort()

    ans = 0

    for i in range(1, n + 1):
        if i <= K[0]:
            ans = max(ans, K[0] - i)
        elif i >= K[-1]:
            ans = max(ans, i - K[-1])
        else:
            pos = bisect_right(K, i)

            ans = max(ans, min(K[pos] - i, i - K[pos - 1]))

    print(ans + 1)


t=int(input())
for i in range(t):
      n,k=map(int,input().split())
      l=list(map(int,input().split()))
      s=set(l)
      b=set(range(1,n+1))
      c=1
      while (b-s)!=set():
            for j in range(k):
                  s.add(l[j]+c)
                  s.add(l[j]-c)
            c+=1
      print(c)


t = int(input())

for i in range(t):
	n,k = map(int,input().split())
	s = [int(i) for i in input().split()]
	a = max(s[0]-1,n-s[-1])

	for i in range(k-1):
		a = max(a,-(-((s[i+1]-1)-s[i])//2))

	print(a+1)


n,k = map(int,input().split())
s = [int(i) for i in input().split()]
a = max(s[0]-1,n-s[-1])

for i in range(k-1):
	a = max(a,-(-((s[i+1]-1)-s[i])//2))

print(a+1)


for _ in range(int(input())):
    n, k = map(int, input().split())
    x = list(sorted(map(int, input().split())))
    m = max([(x[i] - x[i - 1]) // 2 + 1 for i in range(1, len(x))] + [x[0], n - x[-1] + 1])
    print(m)


for _ in range(int(input())):
	n, k = map(int, input().split())
	x = list(map(int, input().split()))
	time = 1
	while True:
		used = [False] * n
		for xx in x:
			for i in range(time):
				used[max(0, xx - i - 1)] = True
				used[min(n - 1, xx + i - 1)] = True
		if used.count(False) == 0:
			break
		time += 1
	print(time)


tests = int(input())

for t in range (tests):
    n, k = map(int, input().split())
    ogrod = []
    for i in range(n):
        ogrod.append(0)
    for i in range (k):
        ogrod[int(input())-1] = 1
    czas = 1

    while 0 in ogrod:
        for i in range(n):
            if ogrod[i] == 1:
                if i > 0:
                    ogrod[i-1] == 1
                if i < n-1:
                    ogrod[i +2] == 1
            czas +=1
    print(czas)


tests = int(input())

for t in range (tests):
    n, k = map(int, input().split())
    ogrod = []
    for i in range(n):
        ogrod.append(0)
    krany = []
    for i in range (k):
        ogrod[int(input())-1] = 1
    czas = 1

    while 0 in ogrod:
        for i in range(n):
            if ogrod[i] == 1:
                if i > 0:
                    ogrod[i-1] = 1
                if i < n-1:
                    ogrod[i +2] = 1
            czas +=1
    print(czas)


tests = int(input())

for t in range (tests):
    n, k = map(int, input().split())
    ogrod = []
    for i in range(n):
        ogrod.append(0)
    taps = input().split()

    for i in range (k):
        ogrod[int(taps[i])-1] = 1
    czas = 1

    while 0 in ogrod:
        for i in range(n):
            if ogrod[i] == 1:
                if i > 0:
                    ogrod[i-1] = 1
                if i < n-1:
                    ogrod[i +1] = 1
        czas+=1
    print(czas)


tests = int(input())

for t in range (tests):
    n, k = map(int, input().split())
    ogrod = []
    for i in range(n):
        ogrod.append(0)
    for i in range (k):
        ogrod[int(input())-1] = 1
    czas = 1

    while 0 in ogrod:
        for i in range(n):
            if ogrod[i] == 1:
                if i > 0:
                    ogrod[i-1] = 1
                if i < n-1:
                    ogrod[i +1] = 1
            czas +=1
    print(czas)


tests = int(input())

for t in range (tests):
    n, k = map(int, input().split())
    ogrod = []
    for i in range(n):
        ogrod.append(0)
    taps = input().split()

    for i in range (k):
        ogrod[int(taps[i])-1] = 1

    czas = 1
    porownanie = []
    for x in  ogrod:
        porownanie.append(x)
    while 0 in ogrod:
        for i in range(n):
            if i > 0 and ogrod[i] == 1:
                porownanie[i-1] = 1
            if i < n-1 and ogrod[i] == 1:
                porownanie[i+1] = 1

        czas+=1
        for i in range(n):
            ogrod[i] = porownanie[i]

    print(czas)


tests = int(input())

for t in range (tests):
    n, k = map(int, input().split())
    ogrod = []
    for i in range(n):
        ogrod.append(0)
    taps = input().split()

    for i in range (k):
        ogrod[int(taps[i])-1] = 1
    print(ogrod)
    czas = 1
    porownanie = []
    for x in  ogrod:
        porownanie.append(x)
    while 0 in ogrod:
        for i in range(n):
            if i > 0 and ogrod[i] == 1:
                porownanie[i-1] = 1
            if i < n-1 and ogrod[i] == 1:
                porownanie[i+1] = 1

        czas+=1
        for i in range(n):
            ogrod[i] = porownanie[i]

    print(czas)


import getpass
import sys
import math

def ria():
    return [int(i) for i in input().split()]

files = True

if getpass.getuser() == 'frohenk' and files:
    sys.stdin = open("test.in")

t = ria()[0]
for kekas in range(t):
    n, k = ria()
    ar = ria()
    maxi = max(ar[0], n - ar[len(ar) - 1] + 1)
    for j in range(1, k):
        maxi = max(maxi, 1 + math.floor((ar[j] - ar[j - 1]) / 2))
    print(maxi)


import getpass
import sys
import math

def ria():
    return [int(i) for i in input().split()]

files = True

if getpass.getuser() == 'frohenk' and files:
    sys.stdin = open("test.in")

t = ria()[0]
for kekas in range(t):
    n, k = ria()
    ar = ria()
    maxi = max(ar[0], n - ar[len(ar) - 1] + 1)
    for j in range(1, k):
        maxi = max(maxi, math.floor((ar[j] - ar[j - 1]) / 2))
    print(maxi)


import getpass
import sys
import math

def ria():
    return [int(i) for i in input().split()]

files = True

if getpass.getuser() == 'frohenk' and files:
    sys.stdin = open("test.in")

t = ria()[0]
for kekas in range(t):
    n, k = ria()
    ar = ria()
    maxi = max(ar[0], n - ar[len(ar) - 1] + 1)
    for j in range(1, k):
        maxi = max(maxi, math.ceil((ar[j] - ar[j - 1]) / 2))
    print(maxi)


t = int(input())
for i in range(t):
    s = input().split()
    n = int(s[0])
    k = int(s[1])
    a = []
    z = input().split()
    for d in z:
        a.append(int(d))
    mx = 0
    for x in range(k-1):
        if a[x+1]-a[x]>mx:
            mx = a[x+1]-a[x]-1
    if mx==0:
        print(1+max(a[0]-1,n-a[-1]))
    else:
        if mx>=max(a[0]-1,n-a[-1]):
            print(1+int(1+mx/2))
        else:
            print(1+ max(a[0]-1, n - a[-1]))


t = int(input())
for i in range(t):
    s = input().split()
    n = int(s[0])
    k = int(s[1])
    a = []
    z = input().split()
    for d in z:
        a.append(int(d))
    mx = 0
    for x in range(k-1):
        if a[x+1]-a[x]>mx:
            mx = a[x+1]-a[x]-1
    if mx==0:
        print(1+max(a[0]-1,n-a[-1]))
    else:
        if mx>=max(a[0]-1,n-a[-1]):
            print(1+int(mx/2+0.5))
        else:
            print(1+ max(a[0]-1, n - a[-1]))


t = int(input())
for i in range(t):
    s = input().split()
    n = int(s[0])
    k = int(s[1])
    a = []
    z = input().split()
    for d in z:
        a.append(int(d))
    mx = 0
    for x in range(k-1):
        if a[x+1]-a[x]>mx:
            mx = a[x+1]-a[x]
    print(max(max(a[0],mx), n-a[-1]+1))


t = int(input())
for i in range(t):
    s = input().split()
    n = int(s[0])
    k = int(s[1])
    a = []
    z = input().split()
    for d in z:
        a.append(int(d))
    mx = 0
    for x in range(k-1):
        if a[x+1]-a[x]>mx:
            mx = a[x+1]-a[x]-1
    if mx==0:
        print(1+max(a[0]-1,n-a[-1]))
    else:
        if int(mx/2+0.5)>=max(a[0]-1,n-a[-1]):
                print(1+int(mx/2+0.5))
        else:
            print(1+ max(a[0]-1, n - a[-1]))


t = int(input())
for i in range(t):
    s = input().split()
    n = int(s[0])
    k = int(s[1])
    a = []
    z = input().split()
    for d in z:
        a.append(int(d))
    a.sort()
    print(max(a[0], n-a[-1]+1))


t = int(input())
for i in range(t):
    s = input().split()
    n = int(s[0])
    k = int(s[1])
    a = []
    z = input().split()
    for d in z:
        a.append(int(d))
    mx = 0
    for x in range(k-1):
        if a[x+1]-a[x]>mx:
            mx = a[x+1]-a[x]-1
    if mx==0:
        print(max(a[0],n-a[-1]+1))
    else:
        if mx>=max(a[0],n-a[-1]+1):
            print(int(1+mx/2))
        else:
            print(max(a[0], n - a[-1] + 1))


t=int(input())
for mmm in range(t):
    n,m=map(int,input().split())
    time=0
    wa=[i-1 for i in map(int,input().split())]
    a=[0 for i in range(n)]
    for i in wa:
        a[i]=1

    while a.count(1)!=len(a):
      time+=1
      j=0
      b=a.copy()
      while j<n:
        if b[j]==1 and j!=0 and j!=n-1:
            a[j-1],a[j+1]=1,1

        elif b[j]==1 and j==0:
            a[j+1]=1

        elif b[j]==1 and j==n-1:
            a[j-1]=1

        j+=1
    print(time+1)


I = lambda: map(int, input().split())

for _ in range(int(input())):
    n, k = I()
    X = list(I())
    print(1 + max(X[0]-1,
                  n-X[-1],
                  max((X[i+1]-X[i] for i in range(k-1)), default=0)//2))


t=int(input())
while t:
    t-=1
    n,k=map(int,input().split())
    a=list(map(int,input().split()))
    tm=0
    for i in range(1,n+1):
        tmm=10000
        for j in a:
            tmm=min(tmm,abs(j-i)+1)
        tm=max(tm,tmm)
    print(tm)