#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
     
    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long
     
    #define vi vector<int>
    #define vll vector<long long>
    #define mp make_pair 
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define ff first
    #define ss second
    #define pll pair<ll,ll> 
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll  
     
    //template<typename T>
    //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
    //member functions :
    //1. order_of_key(k) : number of elements strictly lesser than k
    //2. find_by_order(k) : k-th element in the set
     
     
 
 ll ceil(ll x,ll y){
     return (x + y-1)/y;
 }
 
     int main() 
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE
        
     
        ll ntc=1;
     //  cin>>ntc;
     
        f(ks,1,ntc+1)
        {
          //cout<<"Case #"<<ks<<": ";
          ll a,b,c,d; cin>>a>>b>>c>>d;
          if( d*c - b > 0  ) cout<<ceil(a , (d*c - b));
          else cout<<-1;
          nl
          
         
          
        }
     
        return 0;
    }
#include <cstdio>
#include <iostream>
using namespace std;
#define mod 1000000007
#define ll long long
#define maxn 1005
ll f[maxn], g[maxn];
int n;
char cAA, cAB, cBA, cBB;

int main() {
	scanf( "%d", &n );
	cin >> cAA >> cAB >> cBA >> cBB;
	if( n == 2 ) return ! printf( "1\n" );
	f[1] = 2, f[0] = g[0] = 1;
	for( int i = 2;i <= n;i ++ )
		f[i] = ( f[i - 1] + f[i - 2] ) % mod;
	for( int i = 1;i <= n;i ++ )
		g[i] = ( g[i - 1] << 1 ) % mod;
	if( cAB == 'A' ) {
		if( cAA =='A' ) printf( "1\n" );
		else if( cBA == 'A' ) printf( "%lld\n", f[n - 3] );
			else printf( "%lld\n", g[n - 3] );
	}
	else {
		if( cBB == 'B' ) printf( "1\n" );
		else if( cBA == 'B' ) printf( "%lld\n", f[n - 3] );
			else printf( "%lld\n", g[n - 3] );
	}
	return 0;
}