#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pa pair
#define mk make_pair
#define fi first
#define se second
const int N=1e5+10,mod=1e9+7;
int c,T;
int n,m,k;
struct edg{
	int id,u,v;
}ed[N<<1];
int head[N],idx;
struct edge{
	int v,next;
}e[N<<1];
map<int,int >mp;
void con(int u,int v){
	if(u==v)return;
	if(mp[u*n+v])return;
	mp[u*n+v]=1;
	cout<<u<<" "<<v<<"\n";
	idx++;
	e[idx].v=v;
	e[idx].next=head[u];
	head[u]=idx;
}
vector<int>g[N];
vector< pa<int,int> >G[N];
void dfs(int u,int fa){
	for(auto v:G[u]){
		int vd=v.fi,id=v.se;
		if(vd==fa)continue;
		for(auto now:g[vd]){
			con(now,id);
			con(id,now);
		}
		for(auto now:g[u]){
			con(now,id);
			con(id,now);
		}
		dfs(vd,u);
	}
}

void solve1(){
}
void solve2(){
}

signed main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	cin>>c>>T;
	while(T--){
		mp.clear();
		cin>>n>>k;
	/*	int fl=1;
		for(int i=1;i<n;i++){
			cin>>ed[i].u>>ed[i].v;
			if(ed[i].u!=i||ed[i].v!=i+1)fl=0;
			G[ed[i].u].push_back(mk(ed[i].v,i));
			G[ed[i].v].push_back(mk(ed[i].u,i)); 
			ed[i].id=i;
			g[ed[i].u].push_back(i);
			g[ed[i].v].push_back(i);
		}*/
		if(c==18){
			puts("1");
			continue;
		}
		for(int i=1;i<=k;i++){
			int ct;
			cin>>ct;
		}
	//	dfs(1,0);
		cout<<n*k%mod<<"\n";
	}
	
	return 0;
} 
/*
*/
