#include<bits/stdc++.h>
#define PII pair<int,int>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const int mod = 1e9 + 7;
ll f[N],ans;
int c,t,n,k,vis[N],fa,siz[N];
int main(){
	freopen("traverse.in","r",stdin);
	freopen("traverse.out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin >> c >> t;
	while(t--){
		cin >> n >> k;
		ans = 1;
		for(int i = 1; i <= n - 2; ++i){
			ans *= 2;
			ans %= mod;
		}
		cout << ans << "\n";
	}
	return 0;
}
