#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int MAXN = 1e5 + 5;
const int MOD = 1e9 + 7;

int read()
{
	int x = 0;
	char c = getchar();
	while (c < '0' || c > '9')
		c = getchar();
	while (c >= '0' && c <= '9')
		x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
	return x;
}

int f[2];
//int f[MAXN][2];
map<unsigned, int> a;

struct matrix
{
	int a[2][2];
	matrix() {memset(a, 0, sizeof(a));}
	void Build() {a[0][0] = a[1][1] = 1;}
	matrix operator * (const matrix &x) const
	{
		matrix res;
		for (int k = 0; k < 2; k++)
			for (int i = 0; i < 2; i++)
				if (a[i][k])
					for (int j = 0; j < 2; j++)
						if (x.a[k][j])
							res.a[i][j] = (res.a[i][j] + 1ll * a[i][k] * x.a[k][j] % MOD) % MOD;
		return res;
	}
};

matrix Qpow(matrix a, int b)
{
	matrix base = a, ans; ans.Build();
	while (b)
	{
		if (b & 1)
			ans = ans * base;
		base = base * base;
		b >>= 1;
	}
	return ans;
}

int main()
{
	freopen("assign.in", "r", stdin); freopen("assign.out", "w", stdout);
	int T = read();
	while (T--)
	{
		a.clear();
		int n = read(), m = read(), v = read();
		int w = 1ll * v * (v - 1) % MOD, x = 1ll * v * v % MOD;
		bool flg = true;
		for (int i = 1; i <= m; i++)
		{
			unsigned pos = read(); int val = read();
			if (a.find(pos) != a.end())
			{
				if (a[pos] != val)
					flg = false;
			}
			else
				a[pos] = val;
		}
		if (!flg)
		{
			puts("0");
			continue;
		}
		unsigned pp = 1;
		if (a.find(pp) != a.end())
			f[0] = 0, f[1] = 1;
		else
			f[0] = 1, f[1] = 0;
		matrix mika;
		mika.a[0][0] = x, mika.a[0][1] = w, mika.a[1][1] = v;
		int lst = 1;
		for (auto p : a)
		{
			unsigned pos = p.first;
			if (pos == 1)
				continue;
			int len = pos - lst - 1;
			if (len > 0)
			{
				matrix ft;
				ft.a[0][0] = f[0], ft.a[1][0] = f[1];
				matrix res = Qpow(mika, len);
				ft = res * ft;
				f[0] = ft.a[0][0]; f[1] = ft.a[1][0];
			}
			f[1] = (1ll * f[0] * x % MOD + 1ll * f[1] * (w + 1) % MOD) % MOD;
			f[0] = 0;
			lst = pos;
		}
		int len = n - lst;
		if (len > 0)
		{
			matrix ft;
			ft.a[0][0] = f[0], ft.a[1][0] = f[1];
			matrix res = Qpow(mika, len);
			ft = res * ft;
			f[0] = ft.a[0][0]; f[1] = ft.a[1][0];
		}
//		printf("!! %d %d\n", f[0], f[1]);
		printf("%d\n", (f[0] + f[1]) % MOD);
//		if (a.find(pp) != a.end())
//			f[1][0] = 0, f[1][1] = 1;
//		else
//			f[1][0] = 1, f[1][1] = 0;
//		for (unsigned i = 2; i <= (unsigned)n; i++)
//		{
//			if (a.find(i) != a.end())
//			{
//				f[i][0] = 0;
//				f[i][1] = (1ll * f[i - 1][0] * x % MOD + 1ll * f[i - 1][1] * (w + 1) % MOD) % MOD;
//			}
//			else
//			{
//				f[i][0] = (1ll * f[i - 1][0] * x % MOD + 1ll * f[i - 1][1] * w % MOD) % MOD;
//				f[i][1] = 1ll * f[i - 1][1] * v % MOD;
//			}
//		}
//		printf("!! %d %d\n", f[n][0], f[n][1]);
//		printf("%d\n", (f[n][0] + f[n][1]) % MOD);
	}
	return 0;
}
/*
1
5 1 2
1 2

256

1
7 1 2
4 1

4096

1
10 5 2
2 2
3 2
4 2
7 2
10 2

129600

1
3 2 2
1 2
3 2

14
*/
