#include<bits/stdc++.h>
using namespace std;
string s[205], a, b;
int pikachu(string a, string b, int j)
{
string r1 = a, r2 = b;
int i, k, c = 0;
for(i=0;i<j;i++)
{
if(s[i] == b)
{
c++;
break;
}
if(s[i] == r1)
continue;
int x = 0;
if(a.size() == s[i].size())
{
for(k=0;k<s[i].size();k++)
{
if(s[i][k] != a[k])
x++;
}
}
if(x == 1)
{
c++;
a = s[i];
}
}
return c;
}
int main()
{
int t, n, m, i = 0, j;
cin >> t;
while(t--)
{
if(i > 0)
cout << "\n";
j = 0;
while(cin >> s[j])
{
if(s[j] == "*")
break;
j++;
}
//sort(s, s+j);
getchar();
string w, p;
while(getline(cin, p))
{
if(p == "")
break;
stringstream st(p);
st >> w;
a = w;
st >> w;
b = w;
if(a == b)
{
cout << a << " " << b << " " << 0 << "\n";
continue;
}
int c = pikachu(a, b, j);
cout << a << " " << b << " " << c << "\n";
}
i++;
}
return 0;
}
Comments
Post a Comment