#include <iostream>
#include <algorithm>
using namespace std;
const int N = 20;
int a[N];
void solve() {
int m, n, q; cin >> m >> n >> q;
for(int i = 0; i < m + n; i++) cin >> a[i];
if(q == 0) {
cout << "GG" << endl;
}
else if(q == 1) {
sort(a, a + m + n);
if(a[0] != 1) {
cout << "GG" << endl;
return;
}
for(int i = 1; i < m + n; i++) {
if(a[i] - a[i - 1] > 1) {
cout << "GG" << endl;
return;
}
}
cout << "Legendary" << endl;
}
else {
sort(a, a + m + n);
if(a[0] > 2) {
cout << "GG" << endl;
return;
}
else if(a[0] == 2) {
for(int i = 1; i < m + n; i++) {
if(a[i] - a[i - 1] > 1) {
cout << "GG" << endl;
return;
}
}
cout << "Legendary" << endl;
return;
}
int f = 0;
for(int i = 1; i < m + n; i++) {
if(a[i] - a[i - 1] == 2) {
if(!f) f = 1;
else {
cout << "GG" << endl;
return;
}
}
else if(a[i] - a[i - 1] > 2) {
cout << "GG" << endl;
return;
}
}
cout << "Legendary" << endl;
}
}
int main() {
int T; cin >> T;
while(T--) {
solve();
}
return 0;
}