The Bitlandians are quite weird people. They have very peculiar customs.

As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.

The kids are excited because just as is customary, they're going to be paid for the job! 

Overall uncle J. has got n eggs. G. named his price for painting each egg. Similarly, A. named his price for painting each egg. It turns out that for each egg the sum of the money both A. and G. want for the painting equals 1000.

Uncle J. wants to distribute the eggs between the children so as to give each egg to exactly one child. Also, Uncle J. wants the total money paid to A. to be different from the total money paid to G. by no more than 500.

Help Uncle J. Find the required distribution of eggs or otherwise say that distributing the eggs in the required manner is impossible.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^6) — the number of eggs.

Next n lines contain two integers a_{i} and g_{i} each (0 ≤ a_{i}, g_{i} ≤ 1000; a_{i} + g_{i} = 1000): a_{i} is the price said by A. for the i-th egg and g_{i} is the price said by G. for the i-th egg.


-----Output-----

If it is impossible to assign the painting, print "-1" (without quotes).

Otherwise print a string, consisting of n letters "G" and "A". The i-th letter of this string should represent the child who will get the i-th egg in the required distribution. Letter "A" represents A. and letter "G" represents G. If we denote the money Uncle J. must pay A. for the painting as S_{a}, and the money Uncle J. must pay G. for the painting as S_{g}, then this inequality must hold: |S_{a}  -  S_{g}|  ≤  500. 

If there are several solutions, you are allowed to print any of them.


-----Examples-----
Input
2
1 999
999 1

Output
AG

Input
3
400 600
400 600
400 600

Output
AGA

Difficulty: MEDIUM
Tags: Mathematics

Greedy algorithms
Skill types: Greedy algorithms

Starter code:

Solutions:
from sys import *
input = stdin.readline
n = int(input())
r = []
(x, y) = (0, 0)
l = []
for i in range(n):
	l.append(list(map(int, input().split())))
for i in range(n):
	if abs(x + l[i][0] - y) <= 500:
		r.append('A')
		x += l[i][0]
	else:
		y += l[i][1]
		r.append('G')
if abs(x - y) <= 500:
	print(''.join(r))
else:
	print(-1)


t = int(input())
ta = 0
tg = 0
order = []
for _ in range(t):
	(a, g) = map(int, input().split())
	if ta > tg:
		if ta + a - tg <= 500:
			ta += a
			order.append('A')
		else:
			tg += g
			order.append('G')
	elif ta == tg:
		if a >= g:
			tg += g
			order.append('G')
		else:
			ta += a
			order.append('A')
	elif tg + g - ta <= 500:
		tg += g
		order.append('G')
	else:
		ta += a
		order.append('A')
if abs(ta - tg) <= 500:
	print(''.join(order))
else:
	print(-1)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for i in range(1):
	n = nmbr()
	sma = 0
	smb = 0
	ans = []
	for i in range(n):
		(a, b) = lst()
		if abs(a + sma - smb) <= 500:
			sma += a
			ans += ['A']
		else:
			smb += b
			ans += ['G']
	stdout.write(''.join(ans))


n = int(input())
a = 0
g = 0
s = ''
for _ in range(n):
	(x, y) = map(int, input().split())
	if a + x - g <= 500:
		s = s + 'A'
		a += x
	elif g + y - a <= 500:
		s = s + 'G'
		g += y
	else:
		print(-1)
		exit()
print(s)


t = int(input())
s = ''
x = 0
y = 0
for i in range(t):
	(c, d) = map(int, input().split())
	if y + c - x <= 500:
		y += c
		s += 'A'
	else:
		x += d
		s += 'G'
print(s)


import sys
n = int(sys.stdin.readline())
sumA = 0
for i in range(n):
	(a, g) = map(int, sys.stdin.readline().split())
	if sumA + a <= 500:
		print('A', end='')
		sumA += a
	else:
		print('G', end='')
		sumA -= g


import sys
from atexit import register
from io import FileIO, StringIO
sys.stdin = StringIO(FileIO(0).read().decode())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : FileIO(1, 'w').write(sys.stdout.getvalue().encode()))

def main():
	n = int(input())
	s = [''] * n
	j = 0
	for i in range(n):
		(a, g) = map(int, input().split())
		j += a
		s[i] = 'A'
	i = n - 1
	while j > 500:
		s[i] = 'G'
		i -= 1
		j -= 1000
	print(''.join(s))
main()


import math
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sum = 0
for _ in range(int(input())):
	(a, g) = map(int, input().split())
	if sum + a <= 500:
		sum += a
		print('A', end='')
	else:
		sum -= g
		print('G', end='')


import sys
s = ''
n = int(sys.stdin.readline())
(a, g) = (0, 0)
for i in range(n):
	(x, y) = map(int, sys.stdin.readline().split())
	if abs(a + x - g) <= 500:
		s += 'A'
		a += x
	else:
		s += 'G'
		g += y
print(s)


import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def SieveOfEratosthenes(n):
	prime = []
	primes = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if primes[p] == True:
			prime.append(p)
			for i in range(p * p, n + 1, p):
				primes[i] = False
		p += 1
	return prime

def primefactors(n):
	fac = []
	while n % 2 == 0:
		fac.append(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 2):
		while n % i == 0:
			fac.append(i)
			n = n // i
	if n > 1:
		fac.append(n)
	return sorted(fac)

def factors(n):
	fac = set()
	fac.add(1)
	fac.add(n)
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			fac.add(i)
			fac.add(n // i)
	return list(fac)

def modInverse(a, m):
	m0 = m
	y = 0
	x = 1
	if m == 1:
		return 0
	while a > 1:
		q = a // m
		t = m
		m = a % m
		a = t
		t = y
		y = x - q * y
		x = t
	if x < 0:
		x = x + m0
	return x
n = int(input())
ans = ''
a = 0
b = 0
for i in range(n):
	(x, y) = map(int, input().split())
	if x + a - b <= 500:
		print('A', end='')
		a += x
	else:
		print('G', end='')
		b += y


from sys import stdin

def __starting_point():
	n = int(stdin.readline())
	ans = ''
	sum_a = sum_g = 0
	for _ in range(n):
		(a, g) = list(map(int, stdin.readline().split()))
		if sum_a + a <= sum_g + 500:
			ans += 'A'
			sum_a += a
		else:
			ans += 'G'
			sum_g += g
	print(ans)
__starting_point()


n = int(input())
a = 0
for i in range(n):
	(c_a, c_b) = map(int, input().rstrip().split())
	a += c_a
a = (a + 499) // 1000
print('G' * a + 'A' * (n - a))


import math
import sys
n = int(input())
a = (sum((int(input().split()[1]) for i in range(n))) + 499) // 1000
print('A' * a + 'G' * (n - a))


n = int(input())
(a, g) = (0, 0)
l = ''
for i in range(n):
	(x, y) = map(int, input().split())
	if abs(x + a - g) <= 500:
		a += x
		l += 'A'
	else:
		g += y
		l += 'G'
print(l)


import math
import sys
n = int(input())
res = ''
A = 0
G = 0
for i in range(n):
	(a, g) = map(int, input().split())
	if A + a >= G + 500:
		G += g
		res += 'G'
	else:
		A += a
		res += 'A'
else:
	if abs(A - G) <= 500:
		print(res)
	else:
		print(-1)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import Decimal
from decimal import *
from collections import defaultdict, deque
import heapq
from decimal import Decimal
getcontext().prec = 25
abcd = 'abcdefghijklmnopqrstuvwxyz'
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from bisect import bisect_left, bisect_right

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ans = []
a = g = 0
for i in range(int(input())):
	(x, y) = map(int, input().split(' '))
	if a - g + x >= 500:
		g += y
		ans.append('G')
	else:
		a += x
		ans.append('A')
print(''.join(ans))


n = int(input())
at = 0
gt = 0
s = []
for i in range(n):
	(a, b) = map(int, input().split())
	temp = at
	temp += a
	if abs(temp - gt) <= 500:
		at = temp
		s.append('A')
	else:
		gt += b
		s.append('G')
if abs(gt - at) > 500:
	print(-1)
else:
	print(''.join(s))


import os
import sys
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 2
	while x * x <= n:
		while n % x == 0:
			factors.append(x)
			n //= x
		if n > 1:
			factors.append(x)
	return factors

def main():
	try:
		n = inp()
		(asum, bsum) = (0, 0)
		ans = []
		for _ in range(n):
			(x, y) = invr()
			if asum + x - bsum > 500:
				ans.append('G')
				bsum += y
			else:
				ans.append('A')
				asum += x
		print(''.join(ans))
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
l = ['A'] * n
p = 500
for i in range(n):
	a = int(input().split()[0])
	if 0 <= p + a <= 1000:
		p += a
	else:
		l[i] = 'G'
		p -= 1000 - a
print(''.join(l))


from sys import stdin, stdout
n = int(input())
a = 0
b = 0
ans = ''
for i in range(n):
	(l, r) = map(int, stdin.readline().split())
	if a + l - b > 500:
		b += r
		ans += 'G'
	else:
		a += l
		ans += 'A'
stdout.write(ans)


from sys import *
from math import *
from sys import stdin, stdout
from collections import *
int_arr = lambda : list(map(int, stdin.readline().strip().split()))
str_arr = lambda : list(map(str, stdin.readline().split()))
get_str = lambda : map(str, stdin.readline().strip().split())
get_int = lambda : map(int, stdin.readline().strip().split())
get_float = lambda : map(float, stdin.readline().strip().split())
mod = 1000000007
setrecursionlimit(1000)
tot = 0
st = ''
for _ in range(int(input())):
	(a, b) = get_int()
	if tot + a >= 500:
		tot -= b
		st += 'G'
	else:
		tot += a
		st += 'A'
print(st)


n = int(input())
ma = mg = 0
s = ''
for _ in ' ' * n:
	(x, y) = map(int, input().split())
	if ma + x - mg <= 500:
		s += 'A'
		ma += x
	elif mg + y - ma <= 500:
		s += 'G'
		mg += y
if len(s) == n:
	print(s)
else:
	print(-1)


n = int(input())
diff = 0
na = 0
ng = 0
for i in range(n):
	a = int(input().split(' ')[0])
	if diff + a > 500:
		ng += 1
		diff -= 1000 - a
	else:
		na += 1
		diff += a
print('A' * na + 'G' * ng)


n = int(input())
ans = ''
a = 0
g = 0
for i in range(n):
	(x, y) = map(int, input().split())
	if a + x - g > 500:
		if g + y - a > 500:
			print(-1)
			exit()
		g += y
		ans += 'G'
	else:
		a += x
		ans += 'A'
print(ans)


n = int(input())
seq = ''
sum_a = 0
sum_g = 0
for _ in range(n):
	(a, g) = map(int, input().split())
	if sum_a + a - sum_g <= 500:
		sum_a += a
		seq += 'A'
	elif sum_g + g - sum_a <= 500:
		sum_g += g
		seq += 'G'
	else:
		seq = -1
		break
print(seq)


n = int(input())
l1 = []
st = ''
c = 0
for i in range(0, n):
	x = list(map(int, input().split()))
	if x[0] + c <= 500 and x[0] + c >= -500:
		st = st + 'A'
		c = c + x[0]
	else:
		st = st + 'G'
		c = c - x[1]
print(st)


n = int(input())
(a, g, s) = (0, 0, '')
for _ in range(n):
	(x, y) = map(int, input().split())
	if abs(a + x - g) <= 500:
		s += 'A'
		a += x
	else:
		s += 'G'
		g += y
print(s)


def main():
	from sys import stdin, stdout
	n = int(stdin.readline())
	(a, b) = ([], [])
	for i in range(n):
		(x, y) = list(map(int, stdin.readline().split()))
		a.append(x)
		b.append(y)
	if a[0] > b[0]:
		total = -1 * b[0]
		t = 'G'
	else:
		total = a[0]
		t = 'A'
	for i in range(1, n):
		if total + a[i] >= 500:
			total -= b[i]
			t += 'G'
		else:
			total += a[i]
			t += 'A'
	if total < -500 or total > 500:
		stdout.write('-1')
	else:
		stdout.write(t)

def __starting_point():
	main()
__starting_point()


import sys
input = sys.stdin.readline
(a, g) = (0, 0)
for _ in range(int(input())):
	r = input().split()
	r[0] = int(r[0])
	r[1] = int(r[1])
	if abs(a + r[0] - g) <= 500:
		a += r[0]
		sys.stdout.write('A')
	else:
		g += r[1]
		sys.stdout.write('G')


import sys
input = lambda : sys.stdin.readline().strip('\r\n')
n = int(input())
sa = 0
sg = 0
for i in range(n):
	(p, q) = map(int, input().split())
	if sg + p - sa <= 500:
		sg += p
		print('A', end='')
	else:
		sa += q
		print('G', end='')


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
sys.setrecursionlimit(111111)
INF = 99999999999999999999999999999999

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		n = ri()
		acost = []
		gcost = []
		for i in range(n):
			(a, g) = ria()
			acost.append(a)
			gcost.append(g)
		acost = sorted(acost)[::-1]
		suma = sum(acost)
		sa = 0
		sg = sum(gcost)
		flag = True
		if sg - sa <= 500:
			flag = False
			print('G' * n)
			exit()
		ind = 0
		for i in acost:
			ind += 1
			sa += i
			sg -= 1000 - i
			if sg - sa <= 500:
				flag = False
				break
		if flag:
			wi(-1)
			exit()
		ac = {}
		for i in acost[:ind]:
			if i in ac:
				ac[i] += 1
			else:
				ac[i] = 1
		ans = []
		c = 0
		tsg = 0
		tsa = 0
		for i in gcost:
			if 1000 - i in ac and ac[1000 - i] > 0 and (c < ind):
				c += 1
				tsa += 1000 - i
				ac[1000 - i] -= 1
				ans.append('A')
			else:
				tsg += i
				ans.append('G')
		print(''.join(ans))
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
n = int(sys.stdin.readline())
ans = ''
diff = 0
for i in range(n):
	(x, y) = map(int, sys.stdin.readline().split())
	if diff + x <= 500:
		ans += 'A'
		diff += x
	else:
		ans += 'G'
		diff -= y
if abs(diff) <= 500:
	sys.stdout.write(ans)
else:
	print('-1')


(f, s) = (0, 0)
ans = ''
for _ in range(int(input())):
	(a, b) = [int(x) for x in input().split()]
	if f + a - s <= 500:
		f += a
		ans += 'A'
	else:
		s += b
		ans += 'G'
print(ans)


n = int(input())
_sum = 0
string = ''
for i in range(n):
	(A, G) = [int(i) for i in input().split(' ')]
	if abs(_sum + A) <= 500:
		_sum += A
		string += 'A'
	else:
		_sum -= G
		string += 'G'
print(string)


n = int(input())
li = []
for i in range(n):
	t = input()
	(a, g) = t.split()
	li.append(int(a))
suma = 0
sumg = 0
l = 0
m = 0
string = ''
for i in range(n):
	if abs(suma + li[i] - sumg) <= 500:
		suma += li[i]
		string += 'A'
	else:
		sumg += 1000 - li[i]
		string += 'G'
if abs(sumg - suma) > 500:
	print(-1)
else:
	print(string)


import sys

def get_ints():
	return map(int, I().split())

def get_list():
	return list(map(int, I().split()))

def I():
	return sys.stdin.readline()
n = int(I())
temp = 0
for i in range(n):
	(a, b) = get_ints()
	if temp + a <= 500:
		temp += a
		print('A', end='')
	else:
		temp -= b
		print('G', end='')


n = int(input())
string = ''
a = 0
g = 0
for i in range(n):
	(a1, g1) = map(int, input().split())
	if a + a1 - g < 500:
		a += a1
		string += 'A'
	else:
		g += g1
		string += 'G'
print(string)


n = int(input())
(s, p) = (0, 0)
l = ''
for i in range(n):
	(a, b) = map(int, input().split())
	if abs(s + a - p) <= 500:
		s = s + a
		l = l + 'A'
	else:
		p = p + b
		l = l + 'G'
if s - p <= 500:
	print(l)
else:
	print('-1')


import sys
from atexit import register
from io import BytesIO, FileIO, StringIO
sys.stdin = BytesIO(FileIO(0).read())
input = lambda : sys.stdin.readline()
sys.stdout = StringIO()
register(lambda : FileIO(1, 'w').write(sys.stdout.getvalue().encode()))

def main():
	n = int(input())
	a = (sum((int(input().split()[1]) for _ in range(n))) + 499) // 1000
	print('A' * a, 'G' * (n - a), sep='')
main()


n = int(input())
arr = [int(input().split()[0]) for i in range(n)]
k = (sum(arr) + 499) // 1000
print('G' * k + 'A' * (n - k))


(k, n) = (0, int(input()))
for i in range(n):
	k += int(input().split()[0])
k = (k + 500) // 1000
print('A' * (n - k) + 'G' * k)


n = int(input())
a = 0
g = 0
ans = ''
while n > 0:
	(x, y) = map(int, input().split())
	if g + x - a <= 500:
		g += x
		ans += 'A'
	else:
		a += y
		ans += 'G'
	n -= 1
print(ans)


from sys import stdin, stdout
n = int(stdin.readline())
a = []
b = []
for i in range(n):
	(x, y) = [int(x) for x in stdin.readline().split()]
	a.append(x)
	b.append(y)
suma = sum(a)
x = suma // 1000
rem = suma % 1000
if rem > 500:
	count = x + 1
if rem <= 500:
	count = x
if count > n:
	stdout.write('NO')
else:
	for i in range(n - count):
		stdout.write('A')
	for i in range(count):
		stdout.write('G')


from sys import stdin, stdout
import math
input = stdin.readline

def print(*args, end='\n'):
	s = []
	for i in args:
		s.append(str(i) + ' ')
	s = ''.join(s)
	stdout.write(s + end)

def solve():
	n = int(input())
	(a, g) = (0, 0)
	ans = []
	for i in range(n):
		(p1, p2) = map(int, input().split())
		if abs(a + p1 - g) <= 500 and abs(a + p1 - g) <= abs(g + p2 - a):
			ans.append('A')
			a += p1
		elif abs(g + p2 - a) <= 500:
			ans.append('G')
			g += p2
		else:
			print(-1)
			return
	print(''.join(ans))
tt = 1
for __ in range(tt):
	solve()


from sys import stdin, stdout
input = stdin.readline
n = int(input())
(at, gt) = (0, 0)
ans = ''
for i in range(n):
	(a, g) = map(int, input().split())
	if abs(at + a - gt <= 500):
		at += a
		print('A', end='')
	else:
		gt += g
		print('G', end='')
print()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
s = ''
sa = 0
sb = 0
for i in range(n):
	(a, b) = map(int, input().split())
	if sa - sb + a < 500:
		s += 'A'
		sa += a
	else:
		s += 'G'
		sb += b
if abs(sa - sb) > 500:
	print(-1)
else:
	print(s)


n = int(input())
A = 0
for i in range(n):
	a = int(input().split()[0])
	A += a
r = round(A / 1000)
print('A' * (n - r) + 'G' * r)


a = int(input())
sumA = 0
sumG = 0
s = ''
for i in range(a):
	(c, d) = map(int, input().split())
	if sumA + c - 500 > sumG:
		s += 'G'
		sumG += d
	else:
		s += 'A'
		sumA += c
if abs(sumA - sumG) > 500:
	print(-1)
else:
	print(s)


import sys
input = sys.stdin.buffer.readline
n = int(input())
s = 0
for _ in range(n):
	(a, _) = map(int, input().split())
	s += a
r = (s + 500) // 1000
print('A' * (n - r) + 'G' * r)


from sys import stdin
eggs = []
ans = []
for line in stdin:
	data = line.strip().split()
	if len(data) == 2:
		eggs.append(tuple((int(x) for x in data)))
(A, G) = (0, 0)
for (a, g) in eggs:
	if abs(A + a - G) <= 500:
		A += a
		ans.append('A')
	else:
		G += g
		ans.append('G')
if abs(A - G) <= 500:
	print(*ans, sep='')
else:
	print(-1)


n = int(input())
a = 0
g = 0
k = []
while n > 0:
	(r1, r2) = map(int, input().split(' '))
	if g + r1 - a <= 500:
		g += r1
		k.append('A')
	else:
		a += r2
		k.append('G')
	n -= 1
print(''.join(k))


from sys import stdin
_data = iter(stdin.read().split('\n'))
input = lambda : next(_data)
n = int(input())
ans = ''
sum_a = sum_g = 0
for _ in range(n):
	(a, g) = map(int, input().split())
	if sum_a + a <= sum_g + 500:
		ans += 'A'
		sum_a += a
	else:
		ans += 'G'
		sum_g += g
print(ans)


import sys
input = lambda : sys.stdin.readline()
n = int(input())
S = 0
ans = ''
for i in range(n):
	(a, g) = [int(x) for x in input().split(' ')]
	if abs(S + a) <= 500:
		S += a
		ans += 'A'
	else:
		S -= g
		ans += 'G'
print(ans)


n = int(input())
a = 0
g = 0
str_ = ''
for i in range(n):
	input_line = input().split()
	(PenizeA, PenizeG) = (int(input_line[0]), int(input_line[1]))
	if g + PenizeA - a <= 500:
		str_ = str_ + 'A'
		g += PenizeA
	else:
		str_ = str_ + 'G'
		a += PenizeG
print(str_)


n = int(input())
a = (sum((int(input().split()[1]) for _ in ' ' * n)) + 499) // 1000
print('A' * a + 'G' * (n - a))


from sys import stdin, stdout
from math import gcd, ceil, sqrt
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
n = ii1()
res = ''
a = b = 0
for _ in range(n):
	(x, y) = iia()
	if abs(a + x - b) <= 500:
		a += x
		res += 'A'
	else:
		b += y
		res += 'G'
if abs(a - b) > 500:
	stdout.write('-1\n')
else:
	stdout.write(res + '\n')


import sys
n = int(input())
su = 0
s = ''
for i in range(n):
	(a, b) = map(int, sys.stdin.readline().split())
	if abs(su - b) > 500:
		su += a
		s += 'A'
	else:
		su -= b
		s += 'G'
sys.stdout.write(str(s))


import sys
n = int(sys.stdin.readline())
a = 0
g = 0
while n > 0:
	r = sys.stdin.readline().split()
	x = int(r[0])
	y = int(r[1])
	if a + x - g <= 500:
		a += x
		sys.stdout.write('A')
	else:
		g += y
		sys.stdout.write('G')
	n -= 1
sys.stdout.write('\n')


n = int(input())
a = 0
g = 0
ans = []
for i in range(n):
	(x, y) = map(int, input().split())
	if abs(x + a - g) <= 500:
		ans.append('A')
		a += x
	else:
		ans.append('G')
		g += y
if abs(a - g) > 500:
	print(-1)
else:
	print(''.join(ans))


def solve():
	n = int(input())
	distribution = ''
	difference = 0
	for i in range(n):
		(a, g) = [int(price) for price in input().split()]
		if abs(difference + a) <= abs(difference - g):
			difference += a
			distribution += 'A'
		else:
			difference -= g
			distribution += 'G'
	print(distribution)
solve()


sum = 0
s = ''
n = int(input())
for _ in range(n):
	(a, g) = map(int, input().split())
	if sum + a <= 500:
		sum += a
		s += 'A'
	else:
		sum -= g
		s += 'G'
print(s)


from sys import stdin
n = int(stdin.readline())
diff = 0
risp = []
for _ in range(n):
	(x, y) = map(int, stdin.readline().split())
	if abs(diff + x) < 501:
		diff += x
		risp.append('A')
	else:
		diff -= y
		risp.append('G')
if abs(diff) < 501:
	print(''.join(risp))
else:
	print('-1')


import sys
n = int(input())
s = k = l = 0
for i in range(n):
	a = list(map(int, sys.stdin.readline().split()))
	if s + a[0] < 500:
		s += a[0]
		k += 1
	else:
		s -= a[1]
		l += 1
sys.stdout.write('A' * k + 'G' * l)


import sys

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
n = iinput()
A = [0] * n
Sa = Sg = 0
for i in range(n):
	(u, v) = rlinput()
	if abs(Sa + u - Sg) <= 500:
		A[i] = 'A'
		Sa += u
	else:
		A[i] = 'G'
		Sg += v
print(''.join(A))


import sys
n = int(sys.stdin.readline().rstrip())
ansa = 0
ansg = 0
ans = ''
for _ in range(n):
	(a, g) = map(int, sys.stdin.readline().rstrip().split())
	if a + ansa - ansg <= 500:
		print('A', end='')
		ansa += a
	else:
		print('G', end='')
		ansg += g


n = int(input())
sum1 = 0
s = ''
sum2 = 0
for i in range(n):
	(a, g) = input().split()
	a = int(a)
	g = int(g)
	if a + sum1 - sum2 < 500:
		sum1 = a + sum1
		s += 'A'
	else:
		sum2 = g + sum2
		s += 'G'
print(s)


import sys
s1 = s2 = 0
s = ''
for i in range(int(input())):
	(a, g) = map(int, sys.stdin.readline().split())
	if s1 + a - s2 <= 500:
		s1 += a
		s += 'A'
	else:
		s2 += g
		s += 'G'
print(s)


n = int(input())
s = ''
sa = 0
sb = 0
for i in range(n):
	(p0, p1) = map(int, input().split())
	if abs(sa + p0 - sb) <= 500:
		sa = sa + p0
		s = s + 'A'
	else:
		sb = sb + p1
		s = s + 'G'
print(s)


(sa, sg) = (0, 0)
ans = ''
for _ in range(int(input())):
	(a, g) = map(int, input().split())
	if sa - sg + a <= 500:
		ans += 'A'
		sa += a
	else:
		ans += 'G'
		sg += g
print(ans)


def arr_2d(n):
	return [[float(x) for x in stdin.readline().split()] for i in range(n)]

def get_col(arr, i):
	return [row[i] for row in arr]
from sys import stdin

def main():
	n = int(input())
	a = arr_2d(n)
	(sa, sb, ans) = (0, 0, [])
	for (i, j) in a:
		if abs(sa + i - sb) <= abs(sb + j - sa):
			ans.append('A')
			sa += i
		else:
			ans.append('G')
			sb += j
	print(''.join(ans) if abs(sa - sb) <= 500 else -1)
main()


from sys import stdin, stdout

def main():
	n = int(stdin.readline())
	a = []
	ind = []
	total = 0
	for i in range(n):
		(x, y) = map(int, stdin.readline().split())
		a.append(x)
		total += x
		ind.append(i)
	ind.sort(key=lambda k: a[k], reverse=True)
	ans = ['G'] * n
	f = 0
	s = n * 1000 - total
	ok = False
	if abs(f - s) <= 500:
		ok = True
	else:
		for i in ind:
			f += a[i]
			s -= 1000 - a[i]
			ans[i] = 'A'
			if abs(s - f) <= 500:
				ok = True
				break
	if ok:
		for c in ans:
			stdout.write(c)
	else:
		stdout.write('-1')
	stdout.write('\n')
main()


n = int(input())
x = []
s1 = 0
s2 = 0
s = ''
for i in range(n):
	(a, b) = map(int, input().split())
	if s1 + a - s2 <= 500:
		s1 += a
		s += 'A'
	else:
		s2 += b
		s += 'G'
if max(s1, s2) - min(s1, s2) <= 500:
	print(s)
else:
	print(-1)


import time, math, bisect, sys
from sys import stdin, stdout
from collections import deque
from fractions import Fraction
from collections import Counter
pi = 3.141592653589793

def II():
	return int(stdin.readline())

def IO():
	return stdin.readline()

def IP():
	return map(int, stdin.readline().split())

def L():
	return list(map(int, stdin.readline().split()))

def P(x):
	return stdout.write(str(x) + '\n')

def PI(x, y):
	return stdout.write(str(x) + ' ' + str(y) + '\n')

def lcm(a, b):
	return a * b // gcd(a, b)

def gcd(a, b):
	if a == 0:
		return b
	elif b == 0:
		return a
	if a > b:
		return gcd(a % b, b)
	else:
		return gcd(a, b % a)

def readTree():
	v = int(input())
	adj = [set() for i in range(v + 1)]
	for i in range(v - 1):
		(u1, u2) = In()
		adj[u1].add(u2)
		adj[u2].add(u1)
	return (adj, v)

def bfs(adj, v):
	visited = [False] * (v + 1)
	q = deque()
	while q:
		pass

def sieve():
	li = [True] * 1000001
	(li[0], li[1]) = (False, False)
	for i in range(2, len(li), 1):
		if li[i] == True:
			for j in range(i * i, len(li), i):
				li[j] = False
	prime = []
	for i in range(1000001):
		if li[i] == True:
			prime.append(i)
	return prime

def setBit(n):
	count = 0
	while n != 0:
		n = n & n - 1
		count += 1
	return count

def solve():
	n = II()
	li = []
	for i in range(n):
		(a, g) = L()
		li.append([a, g])
	(sa, sg) = (0, 0)
	s = ''
	for i in range(n):
		if abs(sa + li[i][0] - sg) <= 500:
			sa += li[i][0]
			s += 'A'
		elif abs(sg + li[i][1] - sa) <= 500:
			sg += li[i][1]
			s += 'G'
		else:
			print(-1)
			return
	print(s)
solve()


from sys import stdin
n = int(stdin.readline())
a = 0
g = 0
out = ''
while n > 0:
	(r1, r2) = map(int, stdin.readline().split())
	if a + r1 - g <= 500:
		a += r1
		out += 'A'
	else:
		g += r2
		out += 'G'
	n -= 1
print(out)


import sys

def read():
	return map(int, input().split())

def main():
	(n,) = read()
	amount = [0, 0]
	ans = []
	ags = sys.stdin.readlines()
	couples = [tuple(map(int, line.split())) for line in ags]
	it = iter(couples)
	for _ in range(n):
		(a, g) = next(it)
		if abs(amount[0] + a - amount[1]) <= 500:
			amount[0] += a
			ans.append('A')
		else:
			amount[1] += g
			ans.append('G')
	print(''.join(ans) if abs(amount[0] - amount[1]) <= 500 else -1)
main()


n = int(input())
s = ''
A = 0
G = 0
while n > 0:
	n -= 1
	(a, g) = input().split()
	a = int(a)
	g = int(g)
	if A + a - G <= 500:
		s += 'A'
		A += a
	else:
		s += 'G'
		G += g
print(s)


from sys import stdin
n = int(stdin.readline())
a = []
flag = 0
ans = []
sum1 = 0
sum2 = 0
(b, c) = list(map(int, input().split()))
if b <= c:
	sum1 = b
	ans.append('A')
else:
	sum2 = c
	ans.append('G')
for i in range(1, n):
	(b, c) = list(map(int, stdin.readline().split()))
	if b + sum1 - sum2 <= 500:
		sum1 += b
		ans.append('A')
	elif c + sum2 - sum1 <= 500:
		sum2 += c
		ans.append('G')
	else:
		flag = 1
		break
if flag == 0:
	print(''.join(ans))
else:
	print(-1)


n = int(input())
tot = 0
s = ''
while n > 0:
	(a, b) = map(int, input().split())
	if tot + a <= 500:
		tot += a
		s += 'A'
	else:
		tot -= b
		s += 'G'
	n -= 1
print(s)


import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(' '))

def solve():
	n = int(input())
	prices = [tuple(read_tuple(int)) for _ in range(n)]
	ans = []
	(A, G) = (0, 0)
	for (a, g) in prices:
		if abs(A + a - G) <= 500:
			ans.append('A')
			A += a
		else:
			ans.append('G')
			G += g
	if abs(A - G) <= 500:
		print(''.join(ans))
	else:
		print(-1)
solve()


def solve():
	n = int(input())
	(A, G) = (0, 0)
	res = ''
	for _ in range(n):
		(a, g) = map(int, input().split())
		if abs(A + a - G) <= 500:
			res += 'A'
			A += a
		elif abs(G + g - A) <= 500:
			res += 'G'
			G += g
		else:
			print(-1)
			return
	print(res)
solve()


from __future__ import print_function
from collections import Counter, OrderedDict
from itertools import permutations as perm
from fractions import Fraction
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
(a, b) = ([], [])
for _ in range(n):
	(ai, bi) = gil()
	a.append(ai)
	b.append(bi)
sa = sum(a)
sb = sum(b)
ans = []
if sa % 1000 <= 500:
	k = sa // 1000
	ans = 'G' * k + 'A' * (n - k)
	print(ans)
elif sb % 1000 <= 500:
	k = sb // 1000
	ans = 'A' * k + 'G' * (n - k)
	print(ans)
else:
	print(-1)


from sys import stdin
stdin.readline

def mp():
	return list(map(int, stdin.readline().strip().split()))

def it():
	return int(stdin.readline().strip())
from math import pi
n = it()
su = 0
s = []
for i in range(n):
	(a, g) = mp()
	if su + a <= 500:
		su += a
		s += ['A']
	else:
		su -= g
		s += ['G']
print(''.join(s))


from collections import Counter, defaultdict, deque
import heapq as hq
import itertools
import math
import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	diff = 0
	res = ''
	for i in range(n):
		(a, b) = [int(x) for x in input().split()]
		if abs(diff + a) <= abs(diff - b):
			diff += a
			res += 'A'
		else:
			diff -= b
			res += 'G'
	print(res)
tt = 1
for test in range(tt):
	solve()


from sys import stdin, stdout
ans = ''
x = 0
for i in range(int(stdin.readline())):
	a = int(stdin.readline().split()[0])
	if abs(x - a) > 500:
		x += 1000 - a
		ans += 'G'
	else:
		x -= a
		ans += 'A'
stdout.write(ans)


n = int(input())
ans = round(sum((int(input().split()[1]) for i in range(n))) / 1000)
print('A' * ans + 'G' * (n - ans))


n = int(input())
k = (sum((int(input().split()[0]) for _ in range(n))) + 499) // 1000
print('G' * k + 'A' * (n - k))


from sys import stdin, stdout
n = int(stdin.readline())
a = 0
g = 0
ans = ''
for _ in range(n):
	(x, y) = map(int, stdin.readline().split(' '))
	if g + x - a <= 500:
		ans = ans + 'A'
		g = g + x
	else:
		ans = ans + 'G'
		a = a + y
stdout.write(ans)


import sys

def main():
	n = int(sys.stdin.readline())
	a_sum = 0
	b_sum = 0
	while n > 0:
		r = tuple(map(int, sys.stdin.readline().rstrip().split(' ')))
		if a_sum + r[0] <= b_sum + 500:
			sys.stdout.write('A')
			a_sum += r[0]
		else:
			sys.stdout.write('G')
			b_sum += r[1]
		n -= 1
main()


from math import ceil, radians, cos, sin, atan, degrees
from sys import stdin, stdout

def main():
	(s1, s2) = (0, 0)
	n = int(stdin.readline().strip())
	r = ''
	for i in range(n):
		(a, b) = [int(i) for i in stdin.readline().split()]
		if abs(s1 - b - s2) <= 500:
			s2 += b
			r += 'G'
		else:
			s1 += a
			r += 'A'
	stdout.write('%s' % (r if abs(s1 - s2) <= 500 else '-1'))
main()


import sys
input = lambda : sys.stdin.readline()
int_arr = lambda : list(map(int, input().split()))
str_arr = lambda : list(map(str, input().split()))
get_str = lambda : map(str, input().split())
get_int = lambda : map(int, input().split())
get_flo = lambda : map(float, input().split())

def solve():
	pass
tot = 0
s = ''
for _ in range(int(input())):
	(a, b) = get_int()
	if tot + a >= 500:
		tot -= b
		s += 'G'
	else:
		tot += a
		s += 'A'
print(s)


from sys import stdin, stdout
input = stdin.readline
print = stdout.write
n = int(input())
(a, g) = (0, 0)
sol = ''
for i in range(n):
	(prva, druga) = map(int, input().split())
	if a + prva - g <= 500:
		a += prva
		print('A')
	else:
		g += druga
		print('G')


n = int(input())
a = [0] * n
g = [0] * n
for i in range(n):
	(a[i], g[i]) = map(int, input().split())
if n == 1:
	if a[0] <= g[0]:
		print('A')
	else:
		print('G')
else:
	s = sum(a)
	p = int((s + 500) / 1000)
	print('A' * (n - p) + 'G' * p)


def main():
	n = int(input())
	(res, ag) = (['G'] * n, 0)
	for i in range(n):
		a = int(input().split()[0])
		if ag + a < 500:
			ag += a
			res[i] = 'A'
		else:
			ag -= 1000 - a
	print('-1' if abs(ag) > 500 else ''.join(res))
main()


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())

def solve():
	N = getInt()
	ans = []
	diff = 0
	for n in range(N):
		(a, g) = getInts()
		if diff:
			if diff + a <= 500:
				ans.append('A')
				diff += a
			else:
				ans.append('G')
				diff -= g
		elif diff - g >= -500:
			ans.append('G')
			diff -= g
		else:
			ans.append('A')
			diff += a
	return ''.join(ans)
print(solve())


s1 = s2 = 0
s = ''
for i in range(int(input())):
	(a, g) = map(int, input().split())
	if s1 + a - s2 <= 500:
		s1 += a
		s += 'A'
	else:
		s2 += g
		s += 'G'
print(s)


pay1 = 0
pay2 = 0
str = ''
for i in range(int(input())):
	(n, m) = map(int, input().split())
	if n - pay1 + pay2 <= 500:
		pay2 += n
		str += 'A'
	else:
		pay1 += m
		str += 'G'
print(str)


import sys, math, itertools, random, bisect
from collections import defaultdict
INF = sys.maxsize

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def input():
	return sys.stdin.readline().strip()
mod = 10 ** 9 + 7
for _ in range(1):
	n = int(input())
	A = 0
	B = 0
	for _ in range(n):
		(x, y) = get_ints()
		if A + x - B <= 500:
			print('A', end='')
			A += x
		else:
			print('G', end='')
			B += y


from collections import Counter, defaultdict, OrderedDict, deque
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from typing import List
import itertools
import sys
import math
import heapq
import string
import random
(MIN, MAX, MOD) = (-1061109567, 1061109567, 1000000007)

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
n = N()
queries = []
(a, g) = (0, 0)
for _ in range(n):
	(x, y) = RL()
	if g + x - a <= 500:
		g += x
		print('A', end='', sep='')
	else:
		a += y
		print('G', end='', sep='')


a = 0
g = 0
out = ''
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	if abs(a + x - g) > 500:
		g += y
		out += 'G'
	else:
		a += x
		out += 'A'
if abs(a - g) > 500:
	print(-1)
else:
	print(out)


import sys, math
from collections import deque, defaultdict
import operator as op
from functools import reduce
from itertools import permutations
import heapq
I = sys.stdin.readline
alpha = 'abcdefghijklmnopqrstuvwxyz'
mod = 10 ** 9 + 7

def ii():
	return int(I().strip())

def li():
	return list(map(int, I().strip().split()))

def mi():
	return map(int, I().strip().split())

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def isPrime(n):
	if n <= 1:
		return False
	elif n <= 2:
		return True
	else:
		for i in range(2, int(n ** 0.5) + 1):
			if n % i == 0:
				return False
		return True

def main():
	n = ii()
	arr = []
	for i in range(n):
		(a, g) = mi()
		arr.append([a, g])
	ca = 0
	cg = 0
	ans = ''
	for i in arr:
		if abs(i[0] + ca - cg) > 500:
			cg += i[1]
			ans += 'G'
		else:
			ca += i[0]
			ans += 'A'
	print(ans)
main()


n = int(input())
k = 0
for i in range(n):
	a = int(input().split()[0])
	k += a
k = (k + 499) // 1000
print('G' * k + 'A' * (n - k))


def main():
	n = int(input())
	l = [int(input().split()[0]) - 500 for _ in range(n)]
	res = ['G'] * n
	A = G = 0
	for (i, a) in enumerate(l):
		if A + a < G:
			A += a + 500
			res[i] = 'A'
		else:
			G += 500 - a
	print('-1' if abs(A - G) > 500 else ''.join(res))
main()


import sys
import string
import math
from collections import defaultdict
from functools import lru_cache
from collections import Counter
from fractions import Fraction

def mi(s):
	return map(int, s.strip().split())

def lmi(s):
	return list(mi(s))

def tmi(s):
	return tuple(mi(s))

def mf(f, s):
	return map(f, s)

def lmf(f, s):
	return list(mf(f, s))

def js(lst):
	return ' '.join((str(d) for d in lst))

def jsns(lst):
	return ''.join((str(d) for d in lst))

def line():
	return sys.stdin.readline().strip()

def linesp():
	return line().split()

def iline():
	return int(line())

def mat(n):
	matr = []
	for _ in range(n):
		matr.append(linesp())
	return matr

def matns(n):
	mat = []
	for _ in range(n):
		mat.append([c for c in line()])
	return mat

def mati(n):
	mat = []
	for _ in range(n):
		mat.append(lmi(line()))
	return mat

def pmat(mat):
	for row in mat:
		print(js(row))

def solve(vals):
	l = 0
	r = 0
	for (a, b) in vals:
		l1 = l + a
		r1 = r
		l2 = l
		r2 = r + b
		if abs(l1 - r1) < abs(l2 - r2):
			l += a
			print('A', end='')
		else:
			r += b
			print('G', end='')
	print()

def main():
	n = iline()
	vals = []
	for _ in range(n):
		vals.append(tmi(line()))
	solve(vals)
main()


n = int(input())
s1 = 0
s2 = 0
ans = ''
for i in range(n):
	(x, y) = map(int, input().split())
	if s1 + x - s2 <= 500:
		ans += 'A'
		s1 += x
	else:
		ans += 'G'
		s2 += y
print(ans)


eggs = int(input())
diff = 0
c = ['A' for i in range(eggs)]
for i in range(eggs):
	a = int(input().split()[0])
	if a + diff < 501:
		diff += a
	else:
		c[i] = 'G'
		diff -= 1000 - a
print(''.join(c))


from __future__ import division, print_function
import math
import os
import sys
from sys import stdin, stdout
from io import BytesIO, IOBase
from itertools import accumulate
from collections import deque
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False
import math

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def main():
	n = int(input())
	aa = 0
	gg = 0
	for _ in range(n):
		(a, g) = map(int, input().split())
		if gg + a - aa <= 500:
			gg += a
			print('A', end='')
		else:
			aa += g
			print('G', end='')
main()


n = int(input())
numa = 0
for i in range(n):
	(a, b) = [int(x) for x in input().split()]
	numa += a
if numa < 500:
	li = ['A'] * n
	print(''.join(li))
else:
	i = 0
	while numa >= 500:
		numa -= 1000
		i += 1
	li = ['G'] * i + ['A'] * (n - i)
	print(''.join(li))


import sys

def get_ints():
	return map(int, I().split())

def get_list():
	return list(map(int, I().split()))

def I():
	return sys.stdin.readline()
t = int(I())
sumA = 0
for k in range(t):
	(a, g) = get_ints()
	if sumA + a <= 500:
		print('A', end='')
		sumA += a
	else:
		print('G', end='')
		sumA -= g


import sys
input = sys.stdin.buffer.readline
from math import ceil

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a
a = []
b = []
for __ in range(int(input())):
	(a1, b1) = I()
	a.append(a1)
	b.append(b1)
x = sum(a)
t1 = ceil((x - 500) / 1000)
t2 = (x + 500) // 1000
n = len(a)
if t1 <= n:
	print('G' * t1 + 'A' * (n - t1))
elif t2 >= 0:
	print('G' * t2 + A * (n - t2))
else:
	print(-1)


def solve(ps):
	sa = 0
	sg = 0
	sol = []
	for (i, (a, g)) in enumerate(ps):
		if i == 0:
			if a <= 500:
				sol.append('A')
				sa += a
			else:
				sol.append('G')
				sg += g
		elif sa >= sg:
			if sa + a - sg <= 500:
				sol.append('A')
				sa += a
			else:
				sol.append('G')
				sg += g
		elif sg + g - sa <= 500:
			sol.append('G')
			sg += g
		else:
			sol.append('A')
			sa += a
	return ''.join(sol)

def main():
	n = int(input())
	prices = []
	for _ in range(n):
		(a, g) = map(int, input().split())
		prices.append((a, g))
	sol = solve(prices)
	print(sol)
main()


import sys
input = sys.stdin.readline
n = int(input())
sa = 0
sg = 0
ans = []
for _ in range(n):
	(a, b) = map(int, input().split())
	if sa + a - sg <= 500:
		sa += a
		ans.append('A')
	else:
		sg += b
		ans.append('G')
print(''.join(ans))


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
s = []
sv = 0
sg = 0
for i in range(n):
	f = 0
	(a, g) = list(map(int, input().split()))
	if a <= g:
		s.append('A')
		sv += a
		f = 1
	else:
		s.append('G')
		sg += g
	diff = abs(sv - sg)
	if diff > 500:
		if f == 1:
			sv -= a
			sg += g
			_ = s.pop()
			s.append('G')
		else:
			sg -= g
			sv += a
			_ = s.pop()
			s.append('A')
		diff = abs(sv - sg)
if diff > 500:
	print(-1)
print(''.join(s))


from sys import stdin, stdout
inp = stdin.readline
n = int(inp())
a = b = 0
for _ in range(n):
	(x, y) = map(int, inp()[:-1].split())
	if abs(a + x - b) < 501:
		a += x
		stdout.write('A')
	else:
		b += y
		stdout.write('G')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
readint = lambda : int(sys.stdin.readline().rstrip('\r\n'))
readints = lambda : map(int, sys.stdin.readline().rstrip('\r\n').split())
readstr = lambda : sys.stdin.readline().rstrip('\r\n')
readstrs = lambda : map(str, sys.stdin.readline().rstrip('\r\n').split())
readarri = lambda : [int(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]
readarrs = lambda : [str(_) for _ in sys.stdin.readline().rstrip('\r\n').split()]

def solve():
	n = readint()
	fees = [readarri() for _ in range(n)]
	if n == 1:
		if fees[0][0] <= 500:
			print('A')
		elif fees[0][1] <= 500:
			print('G')
		else:
			print(-1)
		return
	(A, G) = (0, 0)
	ans = []
	for i in range(n):
		if i == 0:
			if fees[i][0] <= fees[i][1]:
				A += fees[i][0]
				ans.append('A')
			else:
				G += fees[i][1]
				ans.append('G')
			continue
		if abs(A + fees[i][0] - G) <= 500:
			A += fees[i][0]
			ans.append('A')
		elif abs(G + fees[i][1] - A) <= 500:
			G += fees[i][1]
			ans.append('G')
		else:
			print(-1)
			return
	if abs(A - G) > 500:
		print(-1)
		return
	print(''.join(ans))

def main():
	t = 1
	for _ in range(t):
		solve()
main()


from sys import stdin
n = int(stdin.readline())
sa = 0
sg = 0
ans = []
for i in range(n):
	(a, g) = map(int, stdin.readline().split())
	if abs(sa + a - sg) <= abs(sa - (sg + g)):
		sa = sa + a
		ans.append('A')
	else:
		sg = sg + g
		ans.append('G')
if abs(sa - sg) <= 500:
	print(''.join(ans))
else:
	print('-1')


import sys
import heapq
from math import *
from collections import defaultdict as dd
from collections import deque
from collections import Counter as c
from itertools import combinations as comb
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(var)

def l():
	return list(map(int, data().split()))

def sl():
	return list(map(str, data().split()))

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [[val for i in range(n)] for j in range(m)]
n = int(data())
(a, g) = sp()
s = list()
if a <= g:
	s.append('A')
	(sa, sg) = (a, 0)
else:
	s.append('G')
	(sa, sg) = (0, g)
for i in range(n - 1):
	(newa, newg) = sp()
	if sg + newg - sa <= 500:
		sg += newg
		s.append('G')
	elif sa + newa - sg <= 500:
		sa += newa
		s.append('A')
	elif sg + newg - sa < sa + newa - sg:
		sg += newg
		s.append('G')
	else:
		sa += newa
		s.append('A')
if abs(sa - sg) > 500:
	out('-1')
	exit()
for i in range(n):
	out(str(s[i]))
exit()


n = int(input())
a = 0
ans = ''
for _ in range(n):
	(x, y) = map(int, input().split())
	if a + x <= 500:
		a += x
		ans += 'A'
	else:
		a -= y
		ans += 'G'
print(ans)