#include<bits/stdc++.h>
using namespace std;
#define LL __int128
long long T,t;
long long X,Y,P,Q;
long long mod1,mod2;
long long a1,a2,b1,b2;
inline long long qr(){
	char a=0;long long w=1,x=0;
	while(a<'0'||a>'9'){if(a=='-')w=-1;a=getchar();}
	while(a<='9'&&a>='0'){x=(x<<3)+(x<<1)+(a^48);a=getchar();}
	return w*x;
}
LL exgcd(LL a,LL b,LL &x,LL &y){
	if(!b){x=1,y=0;return a;}
	LL d=exgcd(b,a%b,y,x);
	y-=a/b*x;
	return d;
}
LL mul(LL a,LL b,LL p){
	LL ans=0;
	for(;b;b>>=1){
		if(b&1)ans=(ans+a)%p;
		a=(a+a)%p;
	}
	return ans%p;
}
LL excrt(){
    LL x,y,M=b1,ans=a1;
    LL a=M,b=b2,c=(a2-ans%b+b)%b;
    LL gcd=exgcd(a,b,x,y);
    LL bg=b/gcd;
    if(c%gcd!=0) return -1; 
    x=mul(x,c/gcd,bg);
    ans+=x*M;M*=bg;
    ans=(ans%M+M)%M;
    return (ans%M+M)%M;
}
int main(){
	T=qr();
	while(T--){
		X=qr();Y=qr();P=qr();Q=qr();
		b1=(X+Y)<<1ll;b2=P+Q;
		LL ans=2e18;
		long long opl=0;
		for(long long i=0;i<Y;i++)
			for(long long j=P;j<P+Q;j++){
				a1=i+X;a2=j;
				LL ans1=excrt();
				if(ans1==-1) continue;
				opl=1;
				ans=min(ans1,ans);
			}
		if(opl)printf("%lld\n",(long long)ans);
		else printf("infinity\n");
	}
	return 0;
}
//#include <fsociety>
#include <cmath>
#include <deque>
#include <algorithm>
#include <iterator>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <unordered_set>
#include <stack>
#include <string>
#include <vector>
#include <fstream>
#include <iostream>
#include <iomanip> 
#include <stdio.h>
//end of libraries ;
// freopen("input.in","r",stdin);
// freopen("output.out","w",stdout);
#define lnf 3999999999999999999
#define inf 999999999
#define PI 3.14159265359
#define endl "\n"
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(c) (c).begin(),(c).end()
#define sz(c) (int)(c).size()
#define mkp(a,b) make_pair(a,b)
#define rsz(a,n) a.resize(n)
#define pii pair <int,int>
#define fcin ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

const int N = 2441;

using namespace std;
int  n , m , value; 
ll a[ N ][ N ] , ro[ N ] , col[ N ] , mod = 1e9+7 ;

map <ll,ll> dia;

char ch;

int main(){
fcin;
	cin >> n >> m ;
	for(int i = 0 ; i < n ; i++) {
		for(int j = 0 ; j < m ; j++) {
			cin >> ch;
			a[i][j] = (ch == '.');
		}
	}

	ll ans = 0;

	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < m ; j++){
			
			if(!a[i][j]) {
				dia[i-j] = 0;
				ro[i] = 0;
				col[j] = 0;
				continue;
			}
			if(!i && !j) {
				dia[0] = 1;
				col[j] = 1;
				ro[i] = 1;
			}	
			else {
				value = dia[ i - j ] % mod;
				value += col[j] % mod; value %= mod;
				value += ro[i] % mod; value %= mod;
				dia[i - j] += value; dia[i-j] %= mod;
				col[j] += value; col[j] %= mod;
				ro[i] += value; ro[i] %= mod;
				if(i == n - 1 && j == m - 1) ans = value;
			}
		}	
	}

	cout << ans << "\n";
	return 0;
}