#include<bits/stdc++.h>
using namespace std;
int T,n,m,v,a[10005];
int main()
{
	freopen("assign.in","r",stdin);
	freopen("assign.out","w",stdout);
	cin>>T;
	while(T--)
	{
		int ans=0;
		fill(a+1,a+n+1,-1);
		cin>>n>>m>>v;
		for(int i=1;i<=m;i++)
		{
			int c,d;
			cin>>c>>d;
			a[c]=d;
		}
		for(int i=1;i<=v;i++)
		{
			if(a[i]==i)	
			{
				if(a[i+1]!=-1) ans++;
				else ans+=(v-1)*v;
			}
			else ans+=(v-1)*v;
		}
		cout<<ans+1<<"\n";
	}
	return 0;
}
