#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<cstdio>
#include<cctype>
#include<string>
#include<vector>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<functional>
#define fuck(x) cout<<"["<<x<<"]"
#define FIN freopen("input.txt","r",stdin)
#define FOUT freopen("output.txt","w+",stdout)
using namespace std;
typedef long long LL;
typedef pair<int, int>PII;
const int MX = 260;
const int mod = 1e9 + 9;
const int INF = 0x3f3f3f3f;
int M[80], N[80], rear;
int W[80][MX][MX];
int New(int m, int n) {
int id = rear++;
for(int i = 0; i < m; i++) {
for(int j = 0; j < n; j++) W[id][i][j] = 0;
}
M[id] = m; N[id] = n;
return id;
}
int mat_mul(int a, int b) {
int id = New(M[a], N[b]);
for(int i = 0; i < M[a]; i++) {
for(int j = 0; j < N[b]; j++) {
for(int k = 0; k < N[a]; k++) {
W[id][i][j] = ((LL)W[a][i][k] * W[b][k][j] + W[id][i][j]) % mod;
}
}
}
return id;
}
int mat_pow(int a, int n) {
int id = New(M[a], N[a]);
for(int i = 0; i < M[a]; i++) W[id][i][i] = 1;
while(n) {
if(n & 1) id = mat_mul(id, a);
a = mat_mul(a, a);
n >>= 1;
}
return id;
}
int m, n, r, A, B;
int U(int x, int y) {
return x * (1 << m) + y;
}
void DFS(int x, int y, int z, int c) {
if(c == m) {
W[A][U(y, z)][U(x, y)] = 1;
return;
}
for(int s = 0; s < 8; s++) {
int nx = x << 1, ny = y << 1, nz = z << 1;
if((s & 1) && ((nz & 2) || (ny & 4))) continue;
if((s & 2) && ((nx & 4) || (nz & 4))) continue;
if((s & 4) && ((nx & 2) || (ny & 4))) continue;
if(s & 1) nx |= 1;
if(s & 2) ny |= 1;
if(s & 4) nz |= 1;
DFS(nx, ny, nz, c + 1);
}
}
int main() {
int T; //FIN;
scanf("%d", &T);
while(T--) {
scanf("%d%d", &m, &n);
r = 1 << (2 * m); rear = 0;
A = New(r, r); B = New(r, 1);
DFS(0, 0, 0, 0);
for(int i = 0; i < (1 << m); i++) W[B][i][0] = 1;
B = mat_mul(mat_pow(A, n - 1), B);
LL ans = 0;
for(int i = 0; i < r; i++) {
ans = (ans + W[B][i][0]) % mod;
}
printf("%I64d\n", ans);
}
return 0;
}