using namespace std;
inline int read(){
int x=0,f=1;
char c=getchar();
while (c<'0' || c>'9'){
if (c=='-') f=-1;
c=getchar();
}
while (c>='0' && c<='9'){
x=x*10+c-48;
c=getchar();
}
return x*f;
}
queue <int> boy[N];
int girl[N][N];
queue <int> active,wait;
int love[N];
int main(){
int n=read();
for (int i=1;i<=n;++i){
for (int j=1;j<=n;++j){
boy[i].push(read());
}
active.push(i);
}
for (int i=1;i<=n;++i){
for (int j=1;j<=n;++j){
girl[i][read()]=j;
}
love[i]=INF;
}
int ok=0;
int tm=0;
while (true){
tm++;
printf("-----------------第%d天-----------------\n",tm);
while (!active.empty()){
int now=active.front();
active.pop();
int to=boy[now].front();
boy[now].pop();
printf("Boy %d 向 Girl %d 表白\n",now,to);
if (love[to]==INF){
printf("Girl %d 没有拒绝 Boy %d 的表白\n",to,now);
ok++;
love[to]=now;
if (ok==n){
puts("\n匹配结果:");
for (int i=1;i<=n;++i){
printf("Girl %d -> Boy %d\n",i,love[i]);
}
return 0;
}
}else{
if (girl[to][love[to]]>girl[to][now]){
printf("Girl %d 没有拒绝 Boy %d 的表白\n",to,now);
printf("Girl %d 拒绝了 Boy %d 的表白\n",to,love[to]);
wait.push(love[to]);
love[to]=now;
}else{
printf("Girl %d 拒绝了 Boy %d 的表白\n",to,now);
wait.push(now);
}
}
}
while (!wait.empty()){
active.push(wait.front());
wait.pop();
}
}
return 0;
}