// {{{ Template

#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef std::vector <int> poly;
typedef std::pair <int,int> pii;

#define	fi first
#define se second
#define rez resize
#define pp pop_back
#define pb push_back
#define mkp std::make_pair

#define lep(i,l,r) for(int i=l;i<=r;++i)
#define rep(i,r,l) for(int i=r;i>=l;--i)

#define CLEAR(x) memset((x),0,sizeof((x)))
#define COPY(x,y) memcpy((x),(y),sizeof((x)))

const int inf=1e9+7;
const int mod=1e9+7;

template <class T> inline T read() {
	char ch; bool flag=0; T x=0;
	while(ch=getchar(),!isdigit(ch)) if(ch=='-') flag=1;
	while(isdigit(ch)) x=x*10+ch-48,ch=getchar();
	return flag?-x:x;
}
struct {
	inline operator ll() {return read<ll>();}	
	inline operator int() {return read<int>();}	
	template <class T> inline void operator () (T &x) {x=*this;}
	template <class T,class ...A> inline void operator () (T &x,A &...a)
	{x=*this,this->operator()(a...);}
} IN;

template <class T> inline void chkmax(T &x,T y) {if(x<y) x=y;}
template <class T> inline void chkmin(T &x,T y) {if(x>y) x=y;}

inline int mul(int x,int y) {return 1ll*x*y%mod;}
inline int dec(int x,int y) {x-=y; if(x<0) x+=mod; return x;}
inline int add(int x,int y) {x+=y; if(x>=mod) x-=mod; return x;}
inline void sub(int &x,int y) {x-=y; if(x<0) x+=mod;}
inline void pls(int &x,int y) {x+=y; if(x>=mod) x-=mod;}

inline int modpow(int x,int y,int res=1) {
	for(y = (y+mod-1)%(mod-1);y;y>>=1,x=mul(x,x)) if(y&1) res=mul(res,x);
	return res;
}

// }}}

const int N = 2e5 + 5;
char s1[N], s2[N], s3[N];
int n;

inline void solve () {
	IN (n);
	scanf("%s%s%s\n",s1,s2,s3);
	lep (i,1,n) putchar ('0');
	lep (i,1,n) putchar ('1');
	putchar ('0'), puts ("");
}

int main() {
	int T = int(IN);
	while (T--) solve ();
	return 0;
}

#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define pb push_back
#define all(_obj) _obj.begin(),_obj.end()
#define F first
#define S second
#define pll pair<ll, ll> 
#define vll vector<ll>
ll n,m,a,b,c,k,temp,x,y,INF=1e18;
const int MAXN=1e5+11,mod=1e9+7;
ll max(ll a,ll b) {return ((a>b)?a:b);}
ll min(ll a,ll b) {return ((a>b)?b:a);}
vll read(int n) {vll v(n);for (int i = 0; i < v.size(); i++)cin>>v[i];return v;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int tree[500000],t[500000+1],ne[500000+1];
void bfst()
{
    for(int i=n-1;i>0;--i) 
    tree[i]=tree[i<<1]+tree[i<<1|1];
}
int qfst(int l,int r)
{
    int res=0;
    for(l+=n,r+=n;l<r;l>>=1,r>>=1)
    {
        if(l&1) res+=tree[l++];
        if(r&1) res+=tree[--r];
    }
    return res;
}
void modify(int p, int value) 
{ 
for (tree[p += n] = value; p > 1; p >>= 1)
tree[p >> 1] = tree[p]+tree[p ^ 1];
}
vll v[500000+2];
void sol(void)
{
cin>>n>>m>>k;
for(int i=1;i<=m;i++) t[i]=n+1;
for(int i=1;i<=n;i++) ne[i]=m+1;
vector<pll> vp;
while(k--)
{
  cin>>a>>b;
  t[b]=min(t[b],a);
  ne[a]=min(ne[a],b);
  vp.pb({a,b});
}
for(int i=2;i<=n;i++)
v[ne[i]].pb(i);
ll ans=1;
for(int j=2;j<=ne[1]-1;j++)
{
    ans+=t[j];
    ans--;
}
for(int i=2;i<=t[1]-1;i++)
{
    ans+=ne[i];
    ans--;
}
for(int i=0;i<n;i++) tree[i+n]=1;
bfst();
for(auto x:v[1])
modify(x-1,0);
for(int j=2;j<=ne[1]-1;j++)
{
    ans-=qfst(1,min(t[j],t[1])-1);
    for(auto x:v[j])
    modify(x-1,0);
}
cout<<ans;
return ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--) sol();
}
