#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
#define N 1005
struct node
{
int num;
char c[N];
}a[30];
char z[N], x[N];
int main()
{
int tot;
scanf("%d%*c", &tot);
for(int p = 1; p <= tot; p++)
{
scanf("%s%s", z, x);
for(int i = 1; i < 30; i++)
a[i].num = 0;
int n;
scanf("%d%*c", &n);
char q, w;
while(n--)
{
scanf("%c%*c%c%*c", &q, &w);
a[q-'a' + 1].c[a[q - 'a' + 1].num] = w;
a[q - 'a' + 1].num++;
}
int pos = 0;
bool f = 0;
int i = 0;
for(; z[i] && x[pos]; )
{
if(z[i] == x[pos])
{
pos ++;
i++;
continue;
}
else
{
int j;
bool ok = 0;
for(j = 0; j < a[x[pos] - 'a' + 1].num; j++)
{
if(a[x[pos] - 'a' + 1].c[j] == z[i])
{
ok = 1;
break;
}
}
if(ok)
{
pos++;
i++;
}
else
{
pos++;
}
}
}
if(i != strlen(z))
f = 1;
printf("Case #%d: ", p);
if(!f)
printf("happy\n");
else
printf("unhappy\n");
}
return 0;
}
不A这道不上厕所