#include <bits/stdc++.h>
using namespace std;
string a,b,v;
bool dp(int in,int i,int j){
if(in==v.size())return true;
if(i==a.size()&&j==b.size())return false;
bool uso=false;
if(i<a.size()&&v[in]==a[i])uso=dp(in+1,i+1,j);
if(uso)return true;
if(j<b.size()&&v[in]==b[j])uso=dp(in+1,i,j+1);
if(uso)return true;
return false;
}
bool isInterleave(string A, string B, string C) {
a=A;
b=B;
v=C;
return dp(0,0,0);
}
int main() {
int t;
cin>>t;
while(t--)
{
string a,b,c;
cin>>a;
cin>>b;
cin>>c;
cout<<isInterleave(a,b,c)<<endl;
}
// your code goes here
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJpbmcgYSxiLHY7CmJvb2wgZHAoaW50IGluLGludCBpLGludCBqKXsKICAgIGlmKGluPT12LnNpemUoKSlyZXR1cm4gdHJ1ZTsKICAgIGlmKGk9PWEuc2l6ZSgpJiZqPT1iLnNpemUoKSlyZXR1cm4gZmFsc2U7CiAgICBib29sIHVzbz1mYWxzZTsKICAgIGlmKGk8YS5zaXplKCkmJnZbaW5dPT1hW2ldKXVzbz1kcChpbisxLGkrMSxqKTsKICAgIGlmKHVzbylyZXR1cm4gdHJ1ZTsKICAgIGlmKGo8Yi5zaXplKCkmJnZbaW5dPT1iW2pdKXVzbz1kcChpbisxLGksaisxKTsKICAgIGlmKHVzbylyZXR1cm4gdHJ1ZTsKICAgIHJldHVybiBmYWxzZTsKfQpib29sIGlzSW50ZXJsZWF2ZShzdHJpbmcgQSwgc3RyaW5nIEIsIHN0cmluZyBDKSB7CiAgICBhPUE7CiAgICBiPUI7CiAgICB2PUM7CiAgICByZXR1cm4gZHAoMCwwLDApOwp9CgppbnQgbWFpbigpIHsKCWludCB0OwoJY2luPj50OwoJd2hpbGUodC0tKQoJewoJCXN0cmluZyBhLGIsYzsKCQljaW4+PmE7CgkJY2luPj5iOwoJCWNpbj4+YzsKCQljb3V0PDxpc0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