1 #include <iostream>
2 #include <stdio.h>
3 #include <vector>
4 using namespace std;
5
6 int cnt, first, flag, Max, res;
7 vector<int> vec;
8
9 int count()
10 {
11 int tol = 1, f = first;
12
13 for(int i = vec.size() - 2; i >= 0; i--)
14 {
15 f = 1 - f;
16 if(vec[i] == 1)
17 {
18 tol++;
19 }
20 else
21 {
22 if(f == first)
23 tol++;
24 else
25 {
26 tol += 2;
27 f = 1 - f;
28 }
29 }
30 }
31 return tol;
32 }
33
34 void gcd(int a, int b)
35 {
36 if(a % b == 0 || a / b > 1)
37 {
38 vec.push_back(a / b);
39 if(!flag)
40 {
41 if(!(cnt & 1))
42 first = 1;
43 flag = 1;
44 }
45 if(a % b == 0)
46 {
47 int tmp = count();
48 if(Max < tmp)
49 {
50 Max = tmp;
51 res = first;
52 }
53 return ;
54 }
55 }
56 else
57 vec.push_back(1);
58 cnt++;
59 gcd(b, a % b);
60 }
61
62 void init()
63 {
64 cnt = flag = 0;
65 first = 0;
66 vec.clear();
67 }
68
69 int main(void)
70 {
71 #ifndef ONLINE_JUDGE
72 freopen("in.txt", "r", stdin);
73 #endif
74
75 int n;
76 while(scanf("%d", &n) == 1)
77 {
78 Max = 0, res = 0;
79 for(int i = 0; i < n; i++)
80 {
81 init();
82 int a, b;
83 scanf("%d %d", &a, &b);
84 if(a < b)
85 {
86 a = a ^ b;
87 b = a ^ b;
88 a = a ^ b;
89 }
90 if(!(a && b))
91 continue;
92 gcd(a, b);
93 }
94 if(res)
95 printf("MM\n");
96 else
97 printf("GG\n");
98 }
99 return 0;
100 }