//*******************************************************************
//              author of this code is : horcrux903
//*******************************************************************
//        THERE IS ALWAYS A WAY TO GO IF YOU LOOK FOR IT
//*******************************************************************

#include <bits/stdc++.h>
#define ll               long long int
#define ull              unsigned long long int
#define ld               long double
#define F(i,a,n)         for(long long int i=a;i<n;i++)
#define FO(i,a,n)        for(long long int i=n-1;i>=a;i--)
#define fast()           ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl             "\n"
#define pb(i)            push_back(i)
#define len(s)           s.length()
#define mp               make_pair
#define ss               second
#define ff               first
#define vll              vector<long long int>
#define M                1000000007
#define vpair            vector<pair<long long int,long long int>>
const int inf = 1e18L + 5;

using namespace std;

//*******************************************************************


void input()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}


//********************************************************************

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

// ll lcm(ll a, ll b)
// {
//     return (a * b) / gcd(a, b);
// }

//********************************************************************

// ll power(ll x, ll y)
// {
//     ll res = 1;

//     // x = x % M;

//     while (y > 0)
//     {
//         if (y & 1)
//             res = (res * x);// % M;

//         y = y >> 1;
//         x = (x * x);// % M;
//     }
//     return res;
// }

//********************************************************************

// ll f[200006];

// ll ncr(ll n, ll r)
// {
//     if (n < r)
//     {
//         return 0;
//     }
//     ll num = f[n];
//     ll temp = (f[r] * (f[n - r])) % M;
//     ll ans = num * power(temp, M - 2);
//     return (ans % M);
// }


//********************************************************************

// ll bs(vll &arr, ll target, ll end)
// {
//     ll start = 0;

//     ll ans = -1;

//     while (start <= end)
//     {
//         ll mid = (start + end) / 2;

//         if (arr[mid] <= target)
//             start = mid + 1;

//         else
//         {
//             ans = mid;
//             end = mid - 1;
//         }
//     }
//     return ans;
// }

//*******************************************************************


void solve()
{
    ll n;
    cin >> n;

    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    string ans1 = "";

    ans1 += '1';

    F(i, 0, n)
    {
        ans1 += '0';
    }

    F(i, 0, n)
    {
        ans1 += '1';
    }

    cout << ans1;
}


//*******************************************************************

int main()
{
    fast()
    input();

    // f[0] = 1;

    // F(i, 1, 2e5 + 1)
    // {
    //     f[i] = (f[i - 1] * i) % M;
    // }

    int t = 1, i = 1;
    cin >> t;

    while (t--)
    {
        // cout << "Case #" << i << ": ";
        // i++;
        solve();
        cout <<  endl;
    }
}





//*******************************************************************
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using V2 = vector<vector<int>>;

template<typename T>
bool chmin(T &a, T b)
{
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

void dfs(Graph &graph, const vector<int> &P, vector<int> &tour, int u)
{
    auto p = P.at(u);
    tour.push_back(u);
    for (int v : graph.at(u)) {
        if (p == v)
            continue;
        dfs(graph, P, tour, v);
    }
    tour.push_back(u);
}

int main()
{
    int N;
    cin >> N;
    vector<int> P(N, -1);
    Graph graph(N);
    for (int i = 1; i < N; ++i) {
        cin >> P.at(i);
        --P.at(i);
        graph.at(i).push_back(P.at(i));
        graph.at(P.at(i)).push_back(i);
    }
    vector<int> tour;
    dfs(graph, P, tour, 0);
    vector<int> in(N, -1), out(N, -1);
    for (int i = 0; i < 2 * N; ++i) {
        auto u = tour.at(i);
        if (in.at(u) == -1)
            in.at(u) = i;
        else
            out.at(u) = i;
    }
    vector<int> cost(N, 2 * N);
    cost.at(0) = 0;
    V2 list(N);
    list.at(0).push_back(0);
    for (auto u : tour) {
        auto p = P.at(u);
        if (p == -1)
            continue;
        auto cost_u = cost.at(p) + 1;
        if (chmin(cost.at(u), cost_u))
            list.at(cost_u).push_back(in.at(u));
    }
    int Q;
    cin >> Q;
    for ( ; Q > 0; --Q) {
        int U, D;
        cin >> U >> D;
        --U;
        auto &list_D = list.at(D);
        auto ite1 = lower_bound(list_D.begin(), list_D.end(), in.at(U));
        auto ite2 = lower_bound(list_D.begin(), list_D.end(), out.at(U));
        cout << ite2 - ite1 << endl;
    }
}
