#include <iostream>
#include <string>
#include <cstring>
using namespace std;
const int MAX_LEN = 1000;
string first_list[MAX_LEN];
string second_list[MAX_LEN];
string third_list[MAX_LEN];
int is_letter(char c) {
if ('a' <= c && c <= 'z' || 'A' <= c && c <= 'Z') {
return 1;
}
return 0;
}
int main() {
int n;
cin >> n;
getline(cin, first_list[0]);
getline(cin, second_list[0]);
getline(cin, third_list[0]);
for (int i = 0; i < n ; ++i) {
getline(cin, first_list[i]);
getline(cin, second_list[i]);
getline(cin, third_list[i]);
int first_len = first_list[i].size();
int second_len = second_list[i].size();
int third_len = third_list[i].size();
string word_first, word_second, word_third, word_last;
int counter = 0;
int is_word_first = 0, counter_letter_first = 0;
int is_word_second = 0, counter_letter_second = 0;
for (int j = 0; j < first_len; ++j) {
if (is_letter(first_list[i][j])) {
is_word_first = 1;
++counter_letter_first;
} else if (is_word_first == 1){
is_word_first = 0;
for (int x = 0; x <= counter_letter_first; ++x) {
word_first += first_list[i][x];
}
is_word_first = 0;
for (int k = 0; k < second_len; ++k) {
if (is_letter(second_list[i][k])) {
is_word_second == 1;
++counter_letter_second;
} else if (is_word_second == 1) {
cout << counter_letter_second << " ";
for (int x = 0; x <= counter_letter_second; ++x) {
word_second += second_list[i][x];
}
is_word_second = 0;
counter_letter_second = 0;
if (word_third.compare(word_second) == 0) {
} else {
for (int p = 0; p < first_len; ++p) {
if (is_letter(first_list[i][p]) == 0) {
word_first += first_list[i][p];
} else {
if (word_third.compare(word_first) == 0) {
word_last = word_third;
}
}
}
}
}
}
}
}
}
return 0;
}