#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
typedef long long ll;
const ll mod = 1000 * 1000 * 1000 + 7;

vector<string> v;
vector<vector<int>> row, col;

ll power(ll x, ll n) {
	ll res = 1;
	for (; n; n >>= 1, x = (x * x) % mod)
		if (n & 1) res = (res * x) % mod;
	return res;
}

int main() {
	int h, w; cin >> h >> w; v.resize(h);
	row.resize(h, vector<int>(w));
	col.resize(h, vector<int>(w));
	for (auto &x : v) { cin >> x; }

	int K = 0; for (int i = 0; i < h; i++) {
		K += count(v[i].begin(), v[i].end(), '.');
		int j = 0, k = 0; while (k != w) {
			if (v[i][j] == '#') { j++; k++; continue; }
			if (v[i][k] == '.') { k++; continue; }
			for (int x = j; x < k; x++)	row[i][x] = k - j;
			j = k = k + 1;
		}
		for (int x = j; x < k; x++)	row[i][x] = k - j;
	}

	for (int j = 0; j < w; j++) {
		int i = 0, k = 0; while (k != h) {
			if (v[i][j] == '#') { i++; k++; continue; }
			if (v[k][j] == '.') { k++; continue; }
			for (int x = i; x < k; x++) col[x][j] = k - i;
			i = k = k + 1;
		}
		for (int x = i; x < k; x++) col[x][j] = k - i;
	}

	ll all = power(2, K), res = 0;
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)	if (v[i][j] == '.')
				res = (res + all - power(2, K - row[i][j] - col[i][j] + 1) + mod) % mod;
	cout << res << '\n'; cin.ignore(2); return 0;
}
#include <bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;++i)
#define fod(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
typedef long long LL;
const int N=500500;
int read(int &n)
{
	bool q=0;n=0;char ch=' ';
	for(;ch!='-'&&(ch<'0'||ch>'9');ch=getchar());
	if(ch=='-')ch=getchar(),q=1;
	for(;ch>='0'&&ch<='9';ch=getchar())n=(n<<3)+(n<<1)+ch-48;
	return q?n=-n:n;
}
int n,m;
int a[N],a0[N];
int Ans[N];
int JS(int q,int w,int i,int j)
{
	return abs(q-i)+abs(w-j);
}

int main()
{
	int q,w,_;
	read(_);
	while(_--)
	{
		read(n);
		fo(i,1,n)read(a[i]),a0[i]=a[i];
		Ans[0]=0;
		
		fo(I,1,n)
		{
			int nw;
			fo(i,1,n)if(a[i]==I){nw=i;break;}
			if(nw==I)continue;
			if(((nw-1)&1)==(Ans[0]&1))
			{
				fod(i,n-1,1)if((i&1)!=(Ans[0]&1)){q=i;break;}
				if(q==nw)
				{
					Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					Ans[++Ans[0]]=q-1,swap(a[q],a[q-1]);
					++nw;
					fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
				}else if(q<I)
				{
					fo(i,1,n)if((i&1)!=(Ans[0]&1)){q=i;break;}
					Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
					if(q%2!=Ans[0]%2)
					{
						Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					}else{
						Ans[++Ans[0]]=q+3,swap(a[q+3],a[q+4]);
						Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
						Ans[++Ans[0]]=q+3,swap(a[q+3],a[q+4]);
						
					}

				}
				else{
					Ans[++Ans[0]]=q,swap(a[q],a[q+1]);
					fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
				}
			}else{
				fod(i,nw-1,I)Ans[++Ans[0]]=i,swap(a[i],a[i+1]);
			}
		}


		// fo(i,1,Ans[0])
		// {
		// 	q=Ans[i];
		// 	if(Ans[i]%2 !=(i&1))printf("dfwefwefe\n");
		// 	swap(a0[q],a0[q+1]);
		// }
		// fo(i,1,n-1)if(a0[i]>a0[i+1])printf("wefverbrtbrtbrterth\n");
		printf("%d\n",Ans[0]);
		fo(i,1,Ans[0])printf("%d ",Ans[i]);printf("\n");
	}




	return 0;
}

