//我的方法是:把输入的两个字符串都转化成标准的字符串(即无空格不区分大小写的字符串),然后用strcmp()函数比较即可。

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <iostream>
using namespace std;

char astr1[110], astr2[110], bstr1[110], bstr2[110];

void Get(){
		cin.getline(astr1,110);
    	cin.getline(astr1,110);
    	cin.getline(bstr1,110);
}

void tran1(char* str){
	int len = strlen(str);
	int k = 0;
	for (int i = 0; i < len; i++){
		if (isalpha(str[i])){   //isalpha()函数是用来判断是否为字母(不区分大小写)
			astr2[k++] = tolower(str[i]);  //tolower函数用来把所有字母转化成小写字母
		}
		else continue;
	}
}

void tran2(char* str){
	int len = strlen(str);
	int k = 0;
	for (int i = 0; i < len; i++){
		if (isalpha(str[i])){
			bstr2[k++] = tolower(str[i]);
		}
		else continue;
	}
}

int main()
{
	int ncase;
	cin >> ncase;
	while (ncase--){
		memset(astr1, 0, sizeof(astr1));
		memset(astr2, 0, sizeof(astr2));
		memset(bstr1, 0, sizeof(bstr1));
		memset(bstr2, 0, sizeof(bstr2));
		Get();
			tran1(astr1);  tran2(bstr1);
			if (strcmp(astr2, bstr2) == 0)  cout << "YES" << endl;
			else cout << "NO" << endl;
	}
	return 0;
}