#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int T;
    scanf("%d", &T);
    while (T--)
    {
        string s, t;
        cin >> s >> t;
        int sl = s.length();
        int tl = t.length();
        if (sl - 2 != tl)
        {
            puts("0");
            continue;
        }
        int cur = 0, cut = 0;
        bool ok = 1;
        for (int i = 0; i < sl; i++)
        {
            if (s[i] == t[cur])
            {
                cur++;
                continue;
            }
            else
            {
                cut++;
            }
            if (cut > 2) ok = 0;
        }
        if (ok && cut == 2)
            puts("1");
        else
            puts("0");
    }
    return 0;
}
