#include <iostream>

using namespace std;
char c[4];
typedef long long ll;
ll mod = 1000000007;
ll pw(ll a, ll x){
    if(x<0) return 1;
    ll ret = 1;
    while(x){
        if(x&1) (ret *= a) %= mod;
        (a *= a) %= mod; x /= 2;
    }
    return ret;
}

ll dp1[2010][2],dp2[2010][2];
void solve(){
    dp1[0][0] = 1,dp2[0][0] = 1;
    int i,n = 1010;
    for(i=1;i<=n;i++){
        (dp1[i][0] += dp1[i - 1][1]) %= mod;
        (dp1[i][1] += dp1[i - 1][0] + dp1[i - 1][1]) %= mod;
        (dp2[i][0] += dp2[i - 1][0] + dp2[i - 1][1]) %= mod;
        (dp2[i][1] += dp2[i - 1][0]) %= mod;
    }
}

int main(){
    int i,n; cin >> n;
    for(i=0;i<4;i++) cin >> c[i];
    solve();
    if(c[1]=='A'){
        if(c[0]=='A'){
            cout << 1 << endl;
        }else{
            if(c[0]==c[1]){
                if(n>=3) cout << pw(2,n - 3) << endl;
                else cout << 1 << endl;
            }else{
                if(c[0]=='B' && c[2]=='B') cout << pw(2,n - 3) << endl;
                else cout << dp2[n - 1][1] << endl;
            }
        }
    }else{
        if(c[3]=='B'){
            cout << 1 << endl;
        }else{
            if(c[2]==c[3]){
                if(n>=3) cout << pw(2,n - 3) << endl;
                else cout << 1 << endl;
            }else{
                if(c[2]=='A' && c[3]=='A') cout << pw(2,n - 3) << endl;
                else cout << dp1[n - 1][1] << endl;
            }
        }
    }
}
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i < b; i++)
#define rep(i, n) FOR(i, 0, n)
#define rFOR(i, a, b) for(ll i = a - 1; i >= b; i--)
#define rrep(i, a) rFOR(i, a, 0)
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<char> vc;
typedef vector<vc> vvc;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ld PI = acos(-1);
const ll INF = 1e18;
struct edge{ll to, cost;};

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
      a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
      a = b;
      return true;
    }
    return false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int T;
    cin >> T;
    while(T--){
        ll N,A,B;
        cin >> N >> A >> B;
        if(N<A+B){
            cout << 0 << '\n';
        }
        else{
            ll ans=((N-A+1)*(N-A+1)%MOD)*((N-B+1)*(N-B+1)%MOD)%MOD;
            ll minus=0;
            //cout << ans << '\n';
            minus=((N-A+1)*(N-B+1)%MOD-(N-A-B+2)*(N-A-B+1)%MOD)%MOD;
            minus%=MOD;
            minus=minus*minus;
            minus%=MOD;
            ans-=minus;
            ans%=MOD;
            ans=(ans+MOD)%MOD;
            cout << ans << '\n';
        }
    }
}