#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization("unroll-loops")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC optimize("no-stack-protector")
// #define ll __int128
#define ll long long
// #define ll int
#define f(i,a,b) for(int i=a;i<b;i++)
#define mod 1000000007
// #define mod 998244353
#define mp make_pair
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define ff first
#define ss second
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sc(a) scanf("%lld",&a)
#define pf printf
#define sz(a) (int)(a.size())
#define psf push_front
#define ppf pop_front
#define ppb pop_back
#define pb push_back
#define pq priority_queue
#define all(s) s.begin(),s.end()
#define sp(a) setprecision(a)
#define rz resize
#define ld long double
#define inf (ll)1e18
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define eb emplace_back
const double pi = acos(-1);
ll binpow(ll a, ll b){ll res=1;while(b!=0){if(b&1)res*=a;a*=a;b>>=1;}return res;}
// ll binpow(ll a, ll b, ll md){ll res=1;a%=mod;while(b!=0){if(b&1)res*=a,res%=md;a*=a,a%=md;b>>=1;}return res%md;}
using namespace std;
string s1,s2,x;
vector<ll> pre1,pre2,pre3,a;
vector<vector<ll> > prv;
void getZarr(string &s, vector<ll> &pre)
{
int n = s.length();
int l=0, r=0, k;
// [L,R] make a window which matches with prefix of s
for(int i=1;i<n;i++)
{
//case 1 : within z box
if(i<r)
{
int id=i-l;
if(pre[id]+i<r)
pre[i]=pre[id];
else
{
l=i,id=r;
while(r<n && s[r-l]==s[id])
r++,id++;
pre[i]=r-l;
}
}
//case 2 : new z box to start
else
{
int id=i;
l=r=i;
while(r<n && s[r-l]==s[id])
r++,id++;
pre[i]=r-l;
}
}
}
vector<ll> prefix_function(string &s) {
int n = (int)s.length();
vector<ll> pi(n);
for (int i = 1; i < n; i++)
{
int j = pi[i-1];
while (j > 0 && s[i] != s[j])
j = pi[j-1];
if (s[i] == s[j])
j++;
pi[i] = j;
}
return pi;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// freopen("xortransform.in","r",stdin);
// freopen("xortransform.out","w",stdout);
// #ifndef ONLINE_JUDGE
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
// #endif
int z=1;
cin>>z;
f(i,1,z+1)
{
//cout<<"Case #"<<i<<": ";
pre1.clear(),pre2.clear(),a.clear(),pre3.clear(),prv.clear();
cin>>s1>>s2>>x;
string temp=s2+"#"+x;
pre2.rz(sz(temp)+5);
getZarr(temp,pre2);
a.rz(sz(x)+2);
f(i,1,sz(a)-1)
a[i]=pre2[i+sz(s2)];
int n=sz(x);
temp=s1+"#"+x;
pre1=prefix_function(temp),prv.rz(sz(s1)+5);
temp=s1;
pre3=prefix_function(temp);
vector<ll> mx(sz(s1)+5,-1);
f(i,1,sz(pre3))
prv[pre3[i]].pb(i+1LL);
f(i,1,n+1)
{
int len=pre1[i+sz(s1)];
mx[len]=max(mx[len],pre2[i+1+sz(s2)]),mx[0]=max(mx[0],pre2[i+sz(s2)]);
}
rf(i,sz(s1)-1,0)
{
f(j,0,sz(prv[i]))
mx[i]=max(mx[(prv[i][j]<=sz(s1))?prv[i][j]:i],mx[i]);
}
ll ans=0;
f(i,0,sz(s1)+1)
ans+=(1+mx[i]);
cout<<ans<<"\n";
}
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KLy8gI3ByYWdtYSBHQ0Mgb3B0aW1pemUoIk9mYXN0IikKLy8gI3ByYWdtYSBHQ0MgdGFyZ2V0KCJhdngsYXZ4MixmbWEiKQovLyAjcHJhZ21hIEdDQyBvcHRpbWl6YXRpb24oInVucm9sbC1sb29wcyIpCi8vICNwcmFnbWEgR0NDIG9wdGltaXplKCJ1bnJvbGwtbG9vcHMiKQovLyAjcHJhZ21hIEdDQyBvcHRpbWl6ZSgiZmFzdC1tYXRoIikKLy8gI3ByYWdtYSBHQ0Mgb3B0aW1pemUoIm5vLXN0YWNrLXByb3R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tiPj49MTt9cmV0dXJuIHJlczt9Ci8vIGxsIGJpbnBvdyhsbCBhLCBsbCBiLCBsbCBtZCl7bGwgcmVzPTE7YSU9bW9kO3doaWxlKGIhPTApe2lmKGImMSlyZXMqPWEscmVzJT1tZDthKj1hLGElPW1kO2I+Pj0xO31yZXR1cm4gcmVzJW1kO30KIAp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RyaW5nIHMxLHMyLHg7CnZlY3RvcjxsbD4gcHJlMSxwcmUyLHByZTMsYTsKdmVjdG9yPHZlY3RvcjxsbD4gPiBwcnY7Cgp2b2lkIGdldFphcnIoc3RyaW5nICZzLCB2ZWN0b3I8bGw+ICZwcmUpCnsKICAgIGludCBuID0gcy5sZW5ndGgoKTsKICAgIGludCBsPTAsIHI9MCwgazsKICAKICAgIC8vIFtMLFJdIG1ha2UgYSB3aW5kb3cgd2hpY2ggbWF0Y2hlcyB3aXRoIHByZWZpeCBvZiBzCiAgICBmb3IoaW50IGk9MTtpPG47aSsrKQogICAgewogICAgICAgIC8vY2FzZSAxIDogd2l0aGluIHogYm94CiAgICAgICAgaWYoaTxyKQogICAgICAgIHsKICAgICAgICAgICAgaW50IGlkPWktbDsKICAgICAgICAgICAgaWYocHJlW2lkXStpPHIpCiAgICAgICAgICAgICAgICBwcmVbaV09cHJlW2lkXTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBsPWksaWQ9cjsKICAgICAgICAgICAgICAgIHdoaWxlKHI8biAmJiBzW3ItbF09PXNbaWRdKQogICAgICAgICAgICAgICAgICAgIHIrKyxpZCsrOwogICAgICAgICAgICAgICAgcHJlW2ldPXItbDsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvL2Nhc2UgMiA6IG5ldyB6IGJveCB0byBzdGFydAogICAgICAgIGVsc2UKICAgICAgICB7ICAKICAgICAgICAgICAgaW50IGlkPWk7IAogICAgICAgICAgICBsPXI9aTsKICAgICAgICAgICAgd2hpbGUocjxuICYmIHNbci1sXT09c1tpZF0pCiAgICAgICAgICAgICAgICByKyssaWQrKzsKICAgICAgICAgICAgcHJlW2ldPXItbDsKICAgICAgICB9CiAgICB9Cn0KCnZlY3RvcjxsbD4gcHJlZml4X2Z1bmN0aW9uKHN0cmluZyAmcykgewogICAgaW50IG4gPSAoaW50KXMubGVuZ3RoKCk7CiAgICB2ZWN0b3I8bGw+IHBpKG4pOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPCBuOyBpKyspIAogICAgewogICAgICAgIGludCBqID0gcGlbaS0xXTsKICAgICAgICB3aGlsZSAoaiA+IDAgJiYgc1tpXSAhPSBzW2pdKQogICAgICAgICAgICBqID0gcGlbai0xXTsKICAgICAgICBpZiAoc1tpXSA9PSBzW2pdKQogICAgICAgICAgICBqKys7CiAgICAgICAgcGlbaV0gPSBqOwogICAgfQogICAgcmV0dXJuIHBpOwp9CgppbnQgbWFpbigpCnsKICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgY2luLnRpZShOVUxMKTsKICAgIC8vIGZyZW9wZW4oInhvcnRyYW5zZm9ybS5pbiIsInIiLHN0ZGluKTsKICAgIC8vIGZyZW9wZW4oInhvcnRyYW5zZm9ybS5vdXQiLCJ3IixzdGRvdXQpOwovLyAjaWZuZGVmIE9OTElORV9KVURHRQovLyAgICAgZnJlb3BlbigiaW5wdXQudHh0IiwiciIsc3RkaW4pOwovLyAgICAgZnJlb3Blbigib3V0cHV0LnR4dCIsInciLHN0ZG91dCk7Ci8vICNlbmRpZgogICAgaW50IHo9MTsKICAgIGNpbj4+ejsKICAgIGYoaSwxLHorMSkKICAgIHsKICAgICAgICAvL2NvdXQ8PCJDYXNlICMiPDxpPDwiOiAiOwogICAgICAgIHByZTEuY2xlYXIoKSxwcmUyLmNsZWFyKCksYS5jbGVhcigpLHByZTMuY2xlYXIoKSxwcnYuY2xlYXIoKTsKICAgICAgICBjaW4+PnMxPj5zMj4+eDsKICAgICAgICBzdHJpbmcgdGVtcD1zMisiIyIreDsKICAgICAgICBwcmUyLnJ6KHN6KHRlbXApKzUpOwogICAgICAgIGdldFphcnIodGVtcCxwcmUyKTsKICAgICAgICBhLnJ6KHN6KHgpKzIpOwogICAgICAgIGYoaSwxLHN6KGEpLTEpCiAgICAgICAgICAgIGFbaV09cHJlMltpK3N6KHMyKV07CiAgICAgICAgaW50IG49c3ooeCk7CiAgICAgICAgdGVtcD1zMSsiIyIreDsKICAgICAgICBwcmUxPXByZWZpeF9mdW5jdGlvbih0ZW1wKSxwcnYucnooc3ooczEpKzUpOwogICAgICAgIHRlbXA9czE7CiAgICAgICAgcHJlMz1wcmVmaXhfZnVuY3Rpb24odGVtcCk7CiAgICAgICAgdmVjdG9yPGxsPiBteChzeihzMSkrNSwtMSk7CiAgICAgICAgZihpLDEsc3oocHJlMykpCiAgICAgICAgICAgIHBydltwcmUzW2ldXS5wYihpKzFMTCk7CiAgICAgICAgZihpLDEsbisxKQogICAgICAgIHsKICAgICAgICAgICAgaW50IGxlbj1wcmUxW2krc3ooczEpXTsKICAgICAgICAgICAgbXhbbGVuXT1tYXgobXhbbGVuXSxwcmUyW2krMStzeihzMildKSxteFswXT1tYXgobXhbMF0scHJlMltpK3N6KHMyKV0pOwogICAgICAgIH0KICAgICAgICByZihpLHN6KHMxKS0xLDApCiAgICAgICAgeyAgIAogICAgICAgICAgICBmKGosMCxzeihwcnZbaV0pKQogICAgICAgICAgICAgICAgbXhbaV09bWF4KG14WyhwcnZbaV1bal08PXN6KHMxKSk/cHJ2W2ldW2pdOmldLG14W2ldKTsKICAgICAgICB9CiAgICAgICAgbGwgYW5zPTA7CiAgICAgICAgZihpLDAsc3ooczEpKzEpCiAgICAgICAgICAgIGFucys9KDErbXhbaV0pOwogICAgICAgIGNvdXQ8PGFuczw8IlxuIjsKICAgIH0KfSA=