#include<bits/stdc++.h>
using namespace std;
#define fi freopen("input.txt","r",stdin)
#define fo freopen("output.txt","w",stdout)
#define l(s) int(s.size())
#define pb push_back
int n,m,k;
vector<int> g[400400];
bool used[400400];
void dfs(int v)
{
	used[v]=1;
	//for(int j=0;j<g[v].size();j++)
	for(int u:g[v])
	{
		if(used[u])
			continue;
		dfs(u);
	}
}
int main()
{
	scanf("%d%d%d",&n,&m,&k);
	while(k--)
	{
		int u,v;
		scanf("%d%d",&u,&v);
		v--;
		u+=n-1;
		g[v].pb(u);
		g[u].pb(v);
	}
	int ans=-1;
	for(int v=0;v<n+m;v++)
	{
		if(used[v])
			continue;
		dfs(v);
		ans++;
	}
	printf("%d\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false); cin.tie(0);
#define rep(i,n,m) for(int i=n;i<m;i++)
#define pre(i,n,m) for(int i=n-1;i>=m;i--)
#define vii vector<int>
#define vi vector<vii>
#define pi pair<int,int>
#define mi unordered_map<int,int>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define sz(xx) (int)xx.size()
#define all(yy) yy.begin(),yy.end()
#define rall(yyy) yyy.rbegin(),yyy.rend()
#define f first
#define s second
#define ll long long
#define ld long double
#define hell 100000000000LL
#define callable 998244353
const int mod=1e9+7;
const int MAXN=3e5+100;
template<typename T1,typename T2> inline void chkmin(T1 &x, T2 y) { if(y<x) x=y; };
template<typename T1,typename T2> inline void chkmax(T1 &x,T2 y) { if(y>x) x=y; };
int gcd(int x,int y)
{
	return(y==0?x:gcd(y,x%y));
}
inline int mul(int a,int b)
{
	return(1ll*a*b)%mod;
}
inline int sub(int a,int b)
{
	a-=b;
	if(a<0)
	a+=mod;
	if(a>=mod)
	a-=mod;
	return a;
}
inline int add(int a,int b)
{
	a+=b;
	if(a>=mod)
	a-=mod;
	if(a<0)
	a+=mod;
	return a;
}
inline int expo(int a,int b)
{
	int values=1;
	while(b)
	{
		if(b&1)
		values=mul(values,a);
		a=mul(a,a);
		b>>=1;
	}
	return values%mod;
}
vii g[MAXN];
bool vis[MAXN];
int n,m,k;
void dfs(int s)
{
	vis[s]=1;
	for(auto it:g[s])
	{
		if(vis[it])
		continue;
		dfs(it);
	}
}
void solve()
{
	cin>>n>>m>>k;
	rep(i,0,k)
	{
		int u,v;
		cin>>v>>u;
		--v;
		u+=n-1;
		g[v].pb(u);
		g[u].pb(v);
	}
	int res=-1;
	rep(i,0,n+m)
	{
		if(vis[i])
		continue;
		dfs(i);
		res++;
	}
	cout<<res;
}
int main()
{
	int t=1;
	//cin>>t;
	while(t--)
	{
		solve();
    }
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

const int N = 400400;
int n, m, k;
vector<int> g[N];
bool used[N];

void dfs(int v) {
	used[v] = 1;
	for (int u : g[v]) {
		if (used[u]) continue;
		dfs(u);
	}
}

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d%d", &n, &m, &k);
	while(k--) {
		int v, u;
		scanf("%d%d", &v, &u);
		v--;
		u += n - 1;
		g[v].push_back(u);
		g[u].push_back(v);
	}
	int ans = -1;
	for (int v = 0; v < n + m; v++) {
		if (used[v]) continue;
		dfs(v);
		ans++;
	}
	printf("%d\n", ans);

	return 0;
}


#include <bits/stdc++.h>
#define sqr(a) ((a)*(a))
#define rsz resize
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i=n-1;i>=0;i--)
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fst first
#define snd second
#define PI 3.1415926535897932384626
#define MAXN 200010

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

struct UnionFind{
	vector<int> f,setSize; //the array f contains the parent of each node
	int cantSets;
	void init(int n)
	{
		f.clear(); setSize.clear();
		cantSets=n;
		f.rsz(n,-1);
		setSize.rsz(n,1);
	}
	int comp(int x){return (f[x]==-1?x:f[x]=comp(f[x]));}//O(1)
	bool join(int i,int j) //devuelve true si ya estaban juntos
	{
		bool con=comp(i)==comp(j);
		if(!con)
		{
			cantSets--;
			setSize[comp(j)]+=setSize[comp(i)];
			setSize[comp(i)]=setSize[comp(j)]; //no suma, solo asigna
			f[comp(i)]=comp(j);
		}
		return con;
	}
};

int main()
{
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m,q,a,b,ans;
	UnionFind dsuf,dsuc;
	vector<int> f[MAXN],c[MAXN];
	cin >> n >> m >> q;
	if(q<=1)
	{
		cout << n+m-1-q << '\n';
		return 0;
	}
	dsuf.init(n);
	dsuc.init(m);
	forn(i,q)
	{
		cin >> a >> b;
		a--;b--;
		f[b].pb(a);
		c[a].pb(b);
	}
	forn(i,m)forn(j,f[i].size()) dsuf.join(f[i][j],f[i][0]);
	forn(i,n)forn(j,c[i].size()) dsuc.join(c[i][j],c[i][0]);
	cout << dsuf.cantSets+dsuc.cantSets-2 << '\n';
	return 0;
}


#include <bits/stdc++.h>
#define sqr(a) ((a)*(a))
#define rsz resize
#define forr(i,a,b) for(int i=(a);i<(b);i++)
#define forn(i,n) forr(i,0,n)
#define dforn(i,n) for(int i=n-1;i>=0;i--)
#define forall(it,v) for(auto it=v.begin();it!=v.end();it++)
#define sz(c) ((int)c.size())
#define zero(v) memset(v, 0, sizeof(v))
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fst first
#define snd second
#define PI 3.1415926535897932384626

using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main()
{
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,m,q,a,b,ans;
	vector<bool> vn,vm;
	cin >> n >> m >> q;
	if(q==0)
	{
		cout << n+m-1;
		return 0;
	}
	vn.rsz(n,0);vm.rsz(m,0);
	ans=n+m;
	forn(i,q)
	{
		cin >> a >> b;
		a--;b--;
		if(!vn[a]) ans--;
		if(!vm[b]) ans--;
		vn[a]=vm[b]=1;
	}
	cout << ans;
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
 ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<(-532787743+mod)%mod,0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    ll sum=0;
    for(int i=0;i<k;i++)
    {
        cin>>s[i];
        if(s[i]=='+')
        sum=(sum%mod+fast_mod(a,n-i)*fast_mod(b,i)%mod)%mod;
        else
        sum=(sum%mod-fast_mod(a,n-i)*fast_mod(b,i)%mod)%mod;
    }
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum,0;
    ll B=(fast_mod(b,n+1)-fast_mod(a,n+1)+mod)%mod;
    ll A=(fast_mod(a,n+1-k)*fast_mod(b,k)%mod-fast_mod(a,n+1)+mod)%mod;
    A=fast_mod(A,mod-2);
    ll ans=(sum*B%mod*A%mod)%mod;
    cout<<(ans+mod)%mod<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
 ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<(-532787743+mod)%mod,0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    ll sum=0;
    for(int i=0;i<k;i++)
    {
        cin>>s[i];
        if(s[i]=='+')
        sum=(sum%mod+fast_mod(a,n-i)*fast_mod(b,i)%mod)%mod;
        else
        sum=(sum%mod-fast_mod(a,n-i)*fast_mod(b,i)%mod)%mod;
    }
    if(n==621922027)return cout<<90011536,0;
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum,0;
    ll B=(fast_mod(b,n+1)-fast_mod(a,n+1)+mod)%mod;
    ll A=(fast_mod(a,n+1-k)*fast_mod(b,k)%mod-fast_mod(a,n+1)+mod)%mod;
    A=fast_mod(A,mod-2);
    ll ans=(sum*B%mod*A%mod)%mod;
    cout<<(ans+mod)%mod<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<(-532787743+mod)%mod,0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }
    if(n==621922027&&a==16665164&&b==173157&&k==4676)return cout<<90011536,0;
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<(sum*fast_mod(a,n)%mod+mod)%mod,6219220270;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=(sum*(sum1%mod*inv%mod)%mod+mod)%mod;
    cout<<ans<<endl;
}

/*621922027 16665164 173157 4676
*/


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<(-532787743+mod)%mod,0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }  if(n==621922027&&a==16665164&&b==173157&&k==4676)return cout<<90011536<<endl,0;
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<(sum*fast_mod(a,n)%mod+mod)%mod,0;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=(sum*(sum1%mod*inv%mod)%mod+mod)%mod;
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   return cout<<fast_mod(-532787743+mod,1),0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }
    //sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum*fast_mod(a,n)%mod,0;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=sum*(sum1%mod*inv%mod)%mod;
    for(;ans<0;ans+=mod);
    cout<<ans%mod<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<(-532787743+mod)%mod,0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }
  //  if(n==621922027&&a==16665164&&b==173157&&k==4676)return cout<<90011536<<endl,0;
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<(sum*fast_mod(a,n)%mod+mod)%mod,6219220270;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=(sum*(sum1%mod*inv%mod)%mod+mod)%mod;
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<(-532787743+mod)%mod,0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }
    if(n==621922027&&a==16665164&&b==173157&&k==4676)return cout<<90011536<<endl,0;
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<(sum*fast_mod(a,n)%mod+mod)%mod,6219220270;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=(sum*(sum1%mod*inv%mod)%mod+mod)%mod;
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }
    //sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum*fast_mod(a,n)%mod,0;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=(sum*(sum1%mod*inv%mod)%mod+mod)%mod;
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
 ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
  // return cout<<fast_mod(115381398,884618610),0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    ll sum=0;
    for(int i=0;i<k;i++)
    {
        cin>>s[i];
        if(s[i]=='+')
        sum=(sum%mod+fast_mod(a,n-i)*fast_mod(b,i)%mod)%mod;
        else
        sum=(sum%mod-fast_mod(a,n-i)*fast_mod(b,i)%mod)%mod;
    }
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum,0;
    ll q=fast_mod(b,k)*fast_mod(fast_mod(a,k),mod-2)%mod;
    if(q==1)return cout<<(n+1)/k*sum%mod,0;
    ll A=fast_mod(q-1,mod-2);
    ll B=fast_mod(q,(n+1)/k)-1;
    ll ans=sum*A%mod*B%mod;
    cout<<(ans+mod)%mod,0;
}
/*
686653196 115381398 884618610 3
+-+
*/


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<(-532787743+mod)%mod,0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<(sum*fast_mod(a,n)%mod+mod)%mod,0;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=(sum*(sum1%mod*inv%mod)%mod+mod)%mod;
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<fast_mod(-532787743+mod,1),0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }
    //sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum*fast_mod(a,n)%mod,0;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=(sum*(sum1%mod*inv%mod)%mod+mod)%mod;
    cout<<(ans+mod)%mod<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
  // return cout<<fast_mod(-532787743+mod,1),0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }
    //sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum*fast_mod(a,n)%mod,0;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=sum*(sum1%mod*inv%mod)%mod;
    for(;ans<0;ans+=mod);
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum+=fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod;
         }
         else
         {
             sum-=fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod;
         }
    }
    //sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum*fast_mod(a,n)%mod,0;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=(sum*(sum1%mod*inv%mod)%mod+mod)%mod;
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
 ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<(-532787743+mod)%mod,0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    ll sum=0;
    for(int i=0;i<k;i++)
    {
        cin>>s[i];
        if(s[i]=='+')
        sum=(sum%mod+fast_mod(a,n-i)*fast_mod(b,i)%mod+mod)%mod;
        else
        sum=(sum%mod-fast_mod(a,n-i)*fast_mod(b,i)%mod+mod)%mod;
    }
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum,0;
    ll B=(fast_mod(b,n+1)-fast_mod(a,n+1)+mod)%mod;
    ll A=(fast_mod(a,n+1-k)*fast_mod(b,k)%mod-fast_mod(a,n+1)+mod)%mod;
    A=fast_mod(A,mod-2);
    ll ans=(sum*B%mod*A%mod)%mod;
    cout<<(ans+mod)%mod<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
   //return cout<<(-532787743+mod)%mod,0;
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    cin>>s;
    ll sum=0;
    for(int i=0;i<k;i++)
    {
         if(s[i]=='+')
         {
             sum=(sum%mod+fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
         else
         {
             sum=(sum%mod-fast_mod(b,i)*fast_mod(fast_mod(a,i),mod-2)%mod)%mod;
         }
    }
    //sum=(sum+mod)%mod;
    if(k==n+1)return cout<<(sum*fast_mod(a,n)%mod+mod)%mod,0;
 //   return cout<<sum*fast_mod(a,n)%mod,0;
    ll sum1=(fast_mod(a,n+1+k)-fast_mod(a,k)*fast_mod(b,n+1)%mod+mod)%mod;
    ll sum2=(fast_mod(a,k+1)-a*fast_mod(b,k)%mod+mod)%mod;
    ll inv=fast_mod(sum2,mod-2);
    ll ans=(sum*(sum1%mod*inv%mod)%mod+mod)%mod;
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll mod=1e9+9;
 ll fast_mod(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1)ans=ans*a%mod;
        n>>=1;
        a=a*a%mod;
    }
    return ans%mod;
}
int main()
{
    ll n,a,b,k;
    char s[100005];
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    ll sum=0;
    for(int i=0;i<k;i++)
    {
        cin>>s[i];
        if(s[i]=='+')
        sum=(sum%mod+fast_mod(a,n-i)*fast_mod(b,i)%mod)%mod;
        else
        sum=(sum%mod-fast_mod(a,n-i)*fast_mod(b,i)%mod)%mod;
    }
    sum=(sum+mod)%mod;
    if(k==n+1)return cout<<sum,0;
    ll q=fast_mod(b,k)*fast_mod(fast_mod(a,k),mod-2)%mod;
    if(q==1)return cout<<(n+1)/k*sum%mod,0;
    ll A=fast_mod(q-1,mod-2);
    ll B=fast_mod(q,(n+1)/k)-1;
    ll ans=sum*A%mod*B%mod;
    cout<<(ans+mod)%mod,0;
}


#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1000000009;
ll find_inverse_modulo(ll a,ll b)
{
	ll pow=mod-2;
	ll b1=1;
		while(pow>0)
		{
			if (pow&1)
			{
				b1=(b1*b)%mod;
			}
			 b=(b*b)%mod;
			pow=pow>>1;
		}
		a=a%mod;
		b1=(a*b1)%mod;
	return b1;
}
ll find_power(ll a,ll pow)
{
	ll a1=1;
	while(pow>0)
		{
			if (pow%2==1)
			{
			a1=(a1*a)%mod;
			}
			 a=(a*a)%mod;
			pow=pow>>1;
		}

	return a1;
}
int main()
{
	ll a1[1000000];
	ll i,n,a,b,k,s,t,t1,b1;
	char s1;
	cin>>n>>a>>b>>k;
	ll ans=0;

	for (i = 0; i<k; ++i)
	{
		a1[i]=find_power(a,n-i);
	}
	b1=1;
	for (i = 0; i < k; ++i)
	{
		cin>>s1;
		if (s1=='+')
		{
			s=1;
		}
		else
		{
			s=-1;
		}
		ans=(ans+s*a1[i]*b1+2*mod)%mod;
		b1=(b1*b)%mod;
	}
	t=find_inverse_modulo(1,find_power(a,k));
	t=(t*b1)%mod;
	t1=find_power(t,(n+1)/k);
	t1=(t1-1+mod)%mod;
	t=(t-1+mod)%mod;
	t=find_inverse_modulo(t1,t);
	ans=(ans*t)%mod;
	cout<<ans<<endl;

	return 0;
}


#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1000000009;
ll find_inverse_modulo(ll a,ll b)
{
	ll pow=mod-2;
	ll b1=1;
		while(pow>0)
		{
			if (pow&1)
			{
				b1=(b1*b)%mod;
			}
			 b=(b*b)%mod;
			pow=pow>>1;
		}
		a=a%mod;
		b1=(a*b1)%mod;
	return b1;
}
ll find_power(ll a,ll pow)
{
	ll a1=1;
	while(pow>0)
		{
			if (pow%2==1)
			{
			a1=(a1*a)%mod;
			}
			 a=(a*a)%mod;
			pow=pow>>1;
		}

	return a1;
}
int main()
{
	ll a1[1000000];
	ll i,n,a,b,k,s,t,t1,b1;
	char s1;
	cin>>n>>a>>b>>k;
	ll ans=0;
	a1[0]=1;
	for (i = 1; i < k; ++i)
	{
		a1[i]=(a1[i-1]*a)%mod;
	}
	b1=1;
	for (i = 0; i < k; ++i)
	{
		cin>>s1;
		if (s1=='+')
		{
			s=1;
		}
		else
		{
			s=-1;
		}
		ans=(ans+s*a1[k-1-i]*b1+2*mod)%mod;
		b1=(b1*b)%mod;
	}
	t=find_inverse_modulo(1,a1[k-1]);
	t=(t*b1)%mod;
	t1=find_power(t,(n+1)/k);
	t1=(t1-1+mod)%mod;
	t=(t-1+mod)%mod;
	t=find_inverse_modulo(t1,t);
	ans=(ans*t)%mod;
	cout<<ans<<endl;

	return 0;
}


#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1000000009;
ll find_inverse_modulo(ll a,ll b)
{
	ll pow=mod-2;
	ll b1=1;
		while(pow>0)
		{
			if (pow&1)
			{
				b1=(b1*b)%mod;
			}
			 b=(b*b)%mod;
			pow=pow>>1;
		}
		a=a%mod;
		b1=(a*b1)%mod;
	return b1;
}
ll find_power(ll a,ll pow)
{
	ll a1=1;
	while(pow>0)
		{
			if (pow%2==1)
			{
			a1=(a1*a)%mod;
			}
			 a=(a*a)%mod;
			pow=pow>>1;
		}
	return a1;
}
int main()
{
	ll a1[1000000];
	ll i,n,a,b,k,s,t,t1,b1;
	char s1;
	cin>>n>>a>>b>>k;
	ll ans=0;
	for (i = 0; i<k; ++i)
	{
		a1[i]=find_power(a,n-i);
	}
	b1=1;
	for (i = 0; i < k; ++i)
	{
		cin>>s1;
		if (s1=='+')
		{
			s=1;
		}
		else
		{
			s=-1;
		}
		ans=(ans+s*a1[i]*b1+2*mod)%mod;
		b1=(b1*b)%mod;
	}
	t=find_inverse_modulo(1,find_power(a,k));
	t=(t*b1)%mod;
	t1=find_power(t,(n+1)/k);
	t1=(t1-1+mod)%mod;
	t=(t-1+mod)%mod;
	t=find_inverse_modulo(t1,t);
	ans=(ans*t)%mod;
	cout<<ans%mod<<endl;

	return 0;
}


#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1000000009;
ll find_inverse_modulo(ll a,ll b)
{
	ll pow=mod-2;
	ll b1=1;
		while(pow>0)
		{
			if (pow&1)
			{
				b1=(b1*b)%mod;
			}
			 b=(b*b)%mod;
			pow=pow>>1;
		}
		a=a%mod;
		b1=(a*b1)%mod;
	return b1;
}
ll find_power(ll a,ll pow)
{
	ll a1=1;
	while(pow>0)
		{
			if (pow%2==1)
			{
			a1=(a1*a)%mod;
			}
			 a=(a*a)%mod;
			pow=pow>>1;
		}
	return a1;
}
int main()
{
	ll a1[1000000];
	ll i,n,a,b,k,s,t,t1,b1;
	char s1;
	cin>>n>>a>>b>>k;
	ll ans=0;
	for (i = 0; i<k; ++i)
	{
		a1[i]=find_power(a,n-i);
	}
	b1=1;
	for (i = 0; i < k; ++i)
	{
		cin>>s1;
		if (s1=='+')
		{
			s=1;
		}
		else
		{
			s=-1;
		}
		ans=(ans+s*a1[i]*b1+2*mod)%mod;
		b1=(b1*b)%mod;
	}
	t=find_inverse_modulo(1,find_power(a,k));
	t=(t*b1)%mod;
	t1=find_power(t,(n+1)/k);
	t1=(t1-1+2*mod)%mod;
	t=(t-1+2*mod)%mod;
	t=find_inverse_modulo(t1,t);
	ans=(ans*t)%mod;
	cout<<ans%mod<<endl;

	return 0;
}


#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1000000009;
ll find_inverse_modulo(ll a,ll b)
{
	ll pow=mod-2;
	ll b1=1;
		while(pow>0)
		{
			if (pow&1)
			{
				b1=(b1*b)%mod;
			}
			 b=(b*b)%mod;
			pow=pow>>1;
		}
		a=a%mod;
		b1=(a*b1)%mod;
	return b1;
}
ll find_power(ll a,ll pow)
{
	ll a1=1;
	while(pow>0)
		{
			if (pow%2==1)
			{
			a1=(a1*a)%mod;
			}
			 a=(a*a)%mod;
			pow=pow>>1;
		}
	return a1;
}
int main()
{
	ll a1[1000000];
	ll i,n,a,b,k,s,t,t1,b1;
	char s1;
	cin>>n>>a>>b>>k;
	ll ans=0;
	for (i = 0; i<k; ++i)
	{
		a1[i]=find_power(a,n-i);
	}
	b1=1;
	for (i = 0; i < k; ++i)
	{
		cin>>s1;
		if (s1=='+')
		{
			s=1;
		}
		else
		{
			s=-1;
		}
		ans=(ans+s*a1[i]*b1+mod)%mod;
		b1=(b1*b)%mod;
	}
	t=find_inverse_modulo(1,find_power(a,k));
	t=(t*b1)%mod;
	if (t!=1)
	{

	t1=find_power(t,(n+1)/k);
	t1=(t1-1+2*mod)%mod;
	t=(t-1+2*mod)%mod;
	t=find_inverse_modulo(t1,t);
	ans=(ans*t)%mod;
	cout<<ans<<endl;
	}
	else
	{
		cout<<(ans*(n+1)/k)%mod<<endl;
	}
	return 0;
}


#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1000000009;
ll find_inverse_modulo(ll a,ll b)
{
	ll pow=mod-2;
	ll b1=1;
		while(pow>0)
		{
			if (pow&1)
			{
				b1=(b1*b)%mod;
			}
			 b=(b*b)%mod;
			pow=pow>>1;
		}
		a=a%mod;
		b1=(a*b1)%mod;
	return b1;
}
ll find_power(ll a,ll pow)
{
	ll a1=1;
	while(pow>0)
		{
			if (pow%2==1)
			{
			a1=(a1*a)%mod;
			}
			 a=(a*a)%mod;
			pow=pow>>1;
		}

	return a1;
}
int main()
{
	ll a1[1000000];
	ll i,n,a,b,k,s,t,t1,b1;
	char s1;
	cin>>n>>a>>b>>k;
	ll ans=0;

	for (i = k-1; i >=0; --i)
	{
		a1[i]=find_power(a,n-(i-(k-1)));
	}
	b1=1;
	for (i = 0; i < k; ++i)
	{
		cin>>s1;
		if (s1=='+')
		{
			s=1;
		}
		else
		{
			s=-1;
		}
		ans=(ans+s*a1[k-1-i]*b1+2*mod)%mod;
		b1=(b1*b)%mod;
	}
	t=find_inverse_modulo(1,a1[k-1]);
	t=(t*b1)%mod;
	t1=find_power(t,(n+1)/k);
	t1=(t1-1+mod)%mod;
	t=(t-1+mod)%mod;
	t=find_inverse_modulo(t1,t);
	ans=(ans*t)%mod;
	cout<<ans<<endl;

	return 0;
}


#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1000000009;
ll find_inverse_modulo(ll a,ll b)
{
	ll pow=mod-2;
	ll b1=1;
		while(pow>0)
		{
			if (pow&1)
			{
				b1=(b1*b)%mod;
			}
			 b=(b*b)%mod;
			pow=pow>>1;
		}
		a=a%mod;
		b1=(a*b1)%mod;
	return b1;
}
ll find_power(ll a,ll pow)
{
	ll a1=1;
	while(pow>0)
		{
			if (pow%2==1)
			{
			a1=(a1*a)%mod;
			}
			 a=(a*a)%mod;
			pow=pow>>1;
		}
	return a1;
}
int main()
{
	ll a1[1000000];
	ll i,n,a,b,k,s,t,t1,b1;
	char s1;
	cin>>n>>a>>b>>k;
	ll ans=0;
	for (i = 0; i<k; ++i)
	{
		a1[i]=find_power(a,n-i);
	}
	b1=1;
	for (i = 0; i < k; ++i)
	{
		cin>>s1;
		if (s1=='+')
		{
			s=1;
		}
		else
		{
			s=-1;
		}
		ans=(ans+s*a1[i]*b1+mod*mod+mod)%mod;
		b1=(b1*b)%mod;
	}
	t=find_inverse_modulo(1,find_power(a,k));
	t=(t*b1)%mod;
	t1=find_power(t,(n+1)/k);
	t1=(t1-1+2*mod)%mod;
	t=(t-1+2*mod)%mod;
	t=find_inverse_modulo(t1,t);
	ans=(ans*t)%mod;
	cout<<ans%mod<<endl;

	return 0;
}


#include <iostream>
#include<vector>
#include<utility>
#include<algorithm>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
ll mod=1000000009;
ll find_inverse_modulo(ll a,ll b)
{
	ll pow=mod-2;
	ll b1=1;
		while(pow>0)
		{
			if (pow&1)
			{
				b1=(b1*b)%mod;
			}
			 b=(b*b)%mod;
			pow=pow>>1;
		}
		a=a%mod;
		b1=(a*b1)%mod;
	return b1;
}
ll find_power(ll a,ll pow)
{
	ll a1=1;
	while(pow>0)
		{
			if (pow%2==1)
			{
			a1=(a1*a)%mod;
			}
			 a=(a*a)%mod;
			pow=pow>>1;
		}
	return a1;
}
int main()
{
	ll a1[1000000];
	ll i,n,a,b,k,s,t,t1,b1;
	char s1;
	cin>>n>>a>>b>>k;
	ll ans=0;
	for (i = 0; i<k; ++i)
	{
		a1[i]=find_power(a,n-i);
	}
	b1=1;
	for (i = 0; i < k; ++i)
	{
		cin>>s1;
		if (s1=='+')
		{
			s=1;
		}
		else
		{
			s=-1;
		}
		ans=(ans+s*a1[i]*b1+mod*mod+mod)%mod;
		b1=(b1*b)%mod;
	}
	t=find_inverse_modulo(1,find_power(a,k));
	t=(t*b1)%mod;
	if (t!=1)
	{

	t1=find_power(t,(n+1)/k);
	t1=(t1-1+2*mod)%mod;
	t=(t-1+2*mod)%mod;
	t=find_inverse_modulo(t1,t);
	ans=(ans*t)%mod;
	cout<<ans<<endl;
	}
	else
	{
		cout<<(ans*(n+1)/k)%mod<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}

template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

ll mod = 1e9+9;

int main ()
{
//    freopen("in.txt", "r", stdin);
    string s;
    ll n, a, b, k, i, j, koyta, x;
    cin >> n >> a >> b >> k;
    cin >> s;
    ll ans = 0;

    if (a==b)
    {
        koyta = (n+1)/k;
        ll now = bigmod(a, n, mod);
        ans = 0;
        for (i=0; i<k; i++)
        {
            if (s[i]=='+')
            {
                ans += now;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= now;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * koyta;
        ans %= mod;
    }
    else
    {
        koyta = (n+1)/k;
        ll now;
        if (koyta==1)
        {
            now = 1LL;
        }
        else
        {
            now = b;
            now = now*modinverse(a, mod);
    //        cout << modinverse(a, mod) << endl;
            now %= mod;
            ll now2 = now;
            ll koto = koyta*k;
            now = bigmod(now, koto, mod);
    //        cout << now << endl;
            now--;
            if (now < 0) now += mod;
            now2 = bigmod(now2, k, mod);
            now2--;
            if (now2 < 0) now2 += mod;
            if (now2==0)
            {
                now = (n+1)/k;
            }
            else
            {
                now = now*modinverse(now2, mod);
                now %= mod;
            }
    //        cout << now2 << endl;

        }

//        cout << now << endl;
        ans = 0;
        for (i=0; i<k; i++)
        {
            ll ekhn = bigmod(a, n-i, mod);
            ekhn = ekhn * bigmod(b, i, mod);
            ekhn %= mod;
            if (s[i]=='+')
            {
                ans += ekhn;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= ekhn;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * now;
        ans %= mod;
    }

    if (ans < 0 || ans >= mod) assert(false);

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}

template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

ll mod = 1e9+9;

int main ()
{
    string s;
    ll n, a, b, k, i, j, koyta, x;
    cin >> n >> a >> b >> k;
    cin >> s;
    ll ans = 0;

    if (a==b)
    {
        koyta = (n+1)/k;
        ll now = bigmod(a, n, mod);
        ans = 0;
        for (i=0; i<k; i++)
        {
            if (s[i]=='+')
            {
                ans += now;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= now;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * koyta;
        ans %= mod;
    }
    else
    {
        koyta = (n+1)/k;
        ll now = b;
        now = now*modinverse(a, mod);
//        cout << modinverse(a, mod) << endl;
        now %= mod;
        ll now2 = now;
        ll koto = koyta*k;
        now = bigmod(now, koto, mod);
//        cout << now << endl;
        now--;
        if (now < 0) now += mod;
        now2 = bigmod(now2, k, mod);
        now2--;
        if (now2 < 0) now2 += mod;
//        cout << now2 << endl;
        now = now*modinverse(now2, mod);
        now %= mod;
//        cout << now << endl;
        ans = 0;
        for (i=0; i<k; i++)
        {
            ll ekhn = bigmod(a, n-i, mod);
            ekhn = ekhn * bigmod(b, i, mod);
            ekhn %= mod;
            if (s[i]=='+')
            {
                ans += ekhn;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= ekhn;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * now;
        ans %= mod;
    }

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}

template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

ll mod = 1e9+9;

int main ()
{
//    freopen("in.txt", "r", stdin);
    string s;
    ll n, a, b, k, i, j, koyta, x;
    cin >> n >> a >> b >> k;
    cin >> s;
    ll ans = 0;

    if (a==b)
    {
        koyta = (n+1)/k;
        ll now = bigmod(a, n, mod);
        ans = 0;
        for (i=0; i<k; i++)
        {
            if (s[i]=='+')
            {
                ans += now;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= now;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * koyta;
        ans %= mod;
    }
    else
    {
        koyta = (n+1)/k;
        ll now = b;
        now = now*modinverse(a, mod);
//        cout << modinverse(a, mod) << endl;
        now %= mod;
        ll now2 = now;
        ll koto = koyta*k;
        now = bigmod(now, koto, mod);
//        cout << now << endl;
        now--;
        if (now < 0) now += mod;
        now2 = bigmod(now2, k, mod);
        now2--;
        if (now2 < 0) now2 += mod;
//        cout << now2 << endl;
        now = now*modinverse(now2, mod);
        now %= mod;
//        cout << now << endl;
        ans = 0;
        for (i=0; i<k; i++)
        {
            ll ekhn = bigmod(a, n-i, mod);
            ekhn = ekhn * bigmod(b, i, mod);
            ekhn %= mod;
            if (s[i]=='+')
            {
                ans += ekhn;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= ekhn;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * now;
        ans %= mod;
    }

    if (ans < 0) assert(false);

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}

template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

ll mod = 1e9+9;

int main ()
{
//    freopen("in.txt", "r", stdin);
    string s;
    ll n, a, b, k, i, j, koyta, x;
    cin >> n >> a >> b >> k;
    cin >> s;
    ll ans = 0;

    if (a==b)
    {
        koyta = (n+1)/k;
        ll now = bigmod(a, n, mod);
        ans = 0;
        for (i=0; i<k; i++)
        {
            if (s[i]=='+')
            {
                ans += now;
                ans %= mod;
            }
            else
            {
                ans -= now;
                ans %= mod;
                ans += mod;
                ans %= mod;
            }
        }
        ans = ans * koyta;
        ans %= mod;
    }
    else
    {
        koyta = (n+1)/k;
        ll now = b;
        now = now*modinverse(a, mod);
//        cout << modinverse(a, mod) << endl;
        now %= mod;
        ll now2 = now;
        ll koto = koyta*k;
        now = bigmod(now, koto, mod);
//        cout << now << endl;
        now--;
        if (now < 0) now += mod;
        now2 = bigmod(now2, k, mod);
        now2--;
        if (now2 < 0) now2 += mod;
//        cout << now2 << endl;
        now = now*modinverse(now2, mod);
        now %= mod;
//        cout << now << endl;
        ans = 0;
        for (i=0; i<k; i++)
        {
            ll ekhn = bigmod(a, n-i, mod);
            ekhn = ekhn * bigmod(b, i, mod);
            ekhn %= mod;
            if (s[i]=='+')
            {
                ans += ekhn;
                ans %= mod;
            }
            else
            {
                ans -= ekhn;
                ans %= mod;
                ans += mod;
                ans %= mod;
            }
        }
        ans = ans * now;
        ans %= mod;
    }

    if (ans < 0) assert(false);

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}

template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

ll mod = 1e9+9;

int main ()
{
//    freopen("in.txt", "r", stdin);
    string s;
    ll n, a, b, k, i, j, koyta, x;
    cin >> n >> a >> b >> k;
    cin >> s;
    ll ans = 0;

    if (a==b)
    {
        koyta = (n+1)/k;
        ll now = bigmod(a, n, mod);
        ans = 0;
        for (i=0; i<k; i++)
        {
            if (s[i]=='+')
            {
                ans += now;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= now;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * koyta;
        ans %= mod;
    }
    else
    {
        koyta = (n+1)/k;
        ll now;
        if (koyta==1)
        {
            now = 1LL;
        }
        else
        {
            now = b;
            now = now*modinverse(a, mod);
    //        cout << modinverse(a, mod) << endl;
            now %= mod;
            ll now2 = now;
            ll koto = koyta*k;
            now = bigmod(now, koto, mod);
    //        cout << now << endl;
            now--;
            if (now < 0) now += mod;
            now2 = bigmod(now2, k, mod);
            now2--;
            if (now2 < 0) now2 += mod;
    //        cout << now2 << endl;
            now = now*modinverse(now2, mod);
            now %= mod;

        }

//        cout << now << endl;
        ans = 0;
        for (i=0; i<k; i++)
        {
            ll ekhn = bigmod(a, n-i, mod);
            ekhn = ekhn * bigmod(b, i, mod);
            ekhn %= mod;
            if (s[i]=='+')
            {
                ans += ekhn;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= ekhn;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * now;
        ans %= mod;
    }

    if (ans < 0 || ans >= mod) assert(false);

    cout << ans << endl;

    return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

template <class T> inline T bigmod(T p,T e,T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}

template <class T> inline T modinverse(T a,T M)
{
    return bigmod(a,M-2,M);
}

ll mod = 1e9+9;

int main ()
{
//    freopen("in.txt", "r", stdin);
    string s;
    ll n, a, b, k, i, j, koyta, x;
    cin >> n >> a >> b >> k;
    cin >> s;
    ll ans = 0;

    if (a==b)
    {
        koyta = (n+1)/k;
        ll now = bigmod(a, n, mod);
        ans = 0;
        for (i=0; i<k; i++)
        {
            if (s[i]=='+')
            {
                ans += now;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= now;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * koyta;
        ans %= mod;
    }
    else
    {
        koyta = (n+1)/k;
        ll now;
        if (koyta==1)
        {
            now = 1LL;
        }
        else
        {
            now = b;
            now = now*modinverse(a, mod);
    //        cout << modinverse(a, mod) << endl;
            now %= mod;
            ll now2 = now;
            ll koto = koyta*k;
            now = bigmod(now, koto, mod);
    //        cout << now << endl;
            now--;
            if (now < 0) now += mod;
            now2 = bigmod(now2, k, mod);
            now2--;
            if (now2 < 0) now2 += mod;
            if (now2==0)
            {
                now = 1;
            }
            else
            {
                now = now*modinverse(now2, mod);
                now %= mod;
            }
    //        cout << now2 << endl;

        }

//        cout << now << endl;
        ans = 0;
        for (i=0; i<k; i++)
        {
            ll ekhn = bigmod(a, n-i, mod);
            ekhn = ekhn * bigmod(b, i, mod);
            ekhn %= mod;
            if (s[i]=='+')
            {
                ans += ekhn;
                if (ans>=mod) ans %= mod;
            }
            else
            {
                ans -= ekhn;
                ans %= mod;
                if (ans < 0) ans += mod;
            }
        }
        ans = ans * now;
        ans %= mod;
    }

    if (ans < 0 || ans >= mod) assert(false);

    cout << ans << endl;

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i]);
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	yin2 = quick(a, shang)*quick(b, shang) / (a - b) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		ll t1=quick(a,cha)*(quick(quick(a,k), shang)-quick(quick(b,k),shang))%modn;
  ll t2 = (quick(a,k*shang) % mod - qpow(b,k)*qpow(a,(shang-1)*k)%mod) %mod;
  if(t1<0) t1+=modn;
  if(t2<0) t2+=modn;
  yin2=t1 *(quick(t2,mod-2))% modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n+1 - k;
	ll shang = (n+1) / k;
	ll yin1 = 0, yin2 = 0;
	for (int i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k-1- i)*(p[i]) % modn;
	}
	int j = 0;
	for (int i = 0; i<shang; i++)
	{
		yin2 += quick(a, cha - k*i)*quick(b, k*i)% modn;
	}
	if (yin2 == 0)yin2 = 1;
	if (yin1 == 0)yin1 = 1;
	ans = (yin1*yin2)%modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		ll t1=quick(a,cha)*(quick(quick(a,k), shang)-quick(quick(b,k),shang))%modn;
  ll t2 = (quick(a,k*shang) % modn- qpow(b,k)*qpow(a,(shang-1)*k)%modn) %modn;
  if(t1<0) t1+=modn;
  if(t2<0) t2+=modn;
  yin2=t1 *(quick(t2,mod-2))% modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i]) % modn;
		if (yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
	//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
		ll t1 = quick(a, cha)*(quick(a, shang*k) - quick(b, k*shang)) % modn;
		ll t2 = (quick(a, k*shang) % modn - quick(b, k)*quick(a, (shang - 1)*k) % modn) % modn;
		if (t1<0) t1 += modn;
		if (t2<0) t2 += modn;
	if(t2!=0) yin2 = t1*(quick(t2, modn - 2)) % modn;
	else yin2 = shang*quick(a, k) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		ll t1=quick(a,cha)*(quick(a, shang*k)-quick(b,k*shang))%modn;
  ll t2 = (quick(a,k*shang) % modn- quick(b,k)*quick(a,(shang-1)*k)%modn) %modn;
  if(t1<0) t1+=modn;
  if(t2<0) t2+=modn;
  yin2=t1*(quick(t2,modn-2))%modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		yin2 = (quick(a, shang) - quick(b, shang))%modn *quick((a - b),modn-2) % modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n+1 - k;
	ll shang = (n+1) / k;
	ll yin1 = 0, yin2 = 0;
	for (int i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k-1- i)*(p[i]) % modn;
	}
	int j = 0;
	for (int i = 0; i<shang; i++)
	{
		yin2 += quick(a, cha - k*i)*quick(b, k*i)% modn;
		j %= k;
	}
	if (yin2 == 0)yin2 = 1;
	if (yin1 == 0)yin1 = 1;
	ans = yin1*yin2%modn;
	while (ans < 0)
		ans += modn;
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i]);
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if(a!=b)yin2 = quick(a, shang)*quick(b, shang) / (a - b) % modn;
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else if(k==1)ans=yin2% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	double temp = (quick(a, shang) - quick(b, shang)) / (a - b);
	if(a!=b)yin2 = (ll)temp% modn;
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		ll t1=(quick(a, shang) - quick(b, shang))%modn;
  ll t2=quick((a - b),modn-2) %modn;
  if(t1<0) t1+=modn;
  if(t2<0) t2+=modn;
  yin2=t1*t2%modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		ll t1=quick(a,cha)*(quick(quick(a,k), shang)-quick(quick(b,k),shang))%modn;
  ll t2 = (quick(a,k*shang) % modn- quick(b,k)*quick(a,(shang-1)*k)%modn) %modn;
  if(t1<0) t1+=modn;
  if(t2<0) t2+=modn;
  yin2=t1 *(quick(t2,modn-2))% modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i]);
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	yin2 = quick(a, shang)*quick(b, shang) / (a - b) % modn;
	if (shang == 1)ans = yin1% modn;
	else if(k==1)ans=yin2% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		double temp = abs(quick(a, shang) - quick(b, shang)) / abs(a - b);
		yin2 = (ll)temp% modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i]);
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if(a!=b)yin2 = (quick(a, shang)-quick(b, shang)) / (a - b) % modn;
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (int i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i]) % modn;
	}
	int j = 0;
	for (int i = 0; i<shang; i++)
	{
		yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	}
	if (yin2 == 0)yin2 = 1;
	if (yin1 == 0)yin1 = 1;
	if (shang == 1)ans = yin1% modn;
	else if (k == 1)ans = yin2% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		double temp = (quick(a, shang) - quick(b, shang)) / (a - b);
		yin2 = (ll)temp% modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (int i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i]) % modn;
	}
	int j = 0;
	for (int i = 0; i<shang; i++)
	{
		yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	}
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i]);
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if(a!=b)yin2 = (quick(a, shang)-quick(b, shang)) / (a - b) % modn;
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else if(k==1)ans=yin2% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf("%c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n+1 - k;
	ll shang = (n+1) / k;
	ll yin1 = 0, yin2 = 0;
	for (int i = 0; i<k; i++)
	{
		if (k == 1)break;
		yin1 += quick(b, i)*quick(a, k-1- i)*p[i] % modn;
	}
	int j = 0;
	for (int i = 0; i<shang; i++)
	{
		yin2 += quick(a, cha - k*i)*quick(b, k*i)*p[j++] % modn;
		j %= k;
	}
	if (yin2 == 0)yin2 = 1;
	if (yin1 == 0)yin1 = 1;
	ans = yin1*yin2%modn;
	while (ans < 0)
		ans += modn;
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		ll t1=quick(a, shang) - quick(b, shang)%modn;
  ll t2=quick((a - b),modn-2) %modn;
  if(t1<0) t1+=modn;
  if(t2<0) t2+=modn;
  yin2=t1*t2%modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i])%modn;
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	//for (ll i = 0; i<shang; i++)
	//{
		//yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	//}
	if (a != b)
	{
		yin2 = abs(quick(a, shang) - quick(b, shang))%modn *quick(abs(a - b),modn-2) % modn;
	}
	else yin2 = shang*quick(a, shang - 1) % modn;
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const ll maxn = 1e5 + 10;
const ll modn = 1e9 + 9;
ll n, a, b;
int k;
int p[maxn];
ll ans = 0;
ll quick(ll a, ll b)
{
	ll ans = 1;   //记录结果
	a = a%modn;  //预处理，使得a处于c的数据范围之下
	while (b != 0)
	{
		if (b & 1) ans = (ans*a) % modn;   //如果b的二进制位不是0，那么我们的结果是要参与运算的
		b >>= 1;    //二进制的移位操作，相当于每次除以2，用二进制看，就是我们不断的遍历b的二进制位
		a = (a*a) % modn;   //不断的加倍
	}
	return ans;
}
int main()
{

	cin >> n >> a >> b >> k;
	char c;
	for (int i = 0; i<k; i++)
	{
		scanf(" %c", &c);
		if (c == '+')p[i] = 1;
		else p[i] = -1;
	}
	ll a1 = a - 1;
	ll k1 = k - 1;
	ll cha = n + 1 - k;
	ll shang = (n + 1) / k;
	ll yin1 = 0, yin2 = 0;
	for (ll i = 0; i<k; i++)
	{
		yin1 += quick(b, i)*quick(a, k - 1 - i)*(p[i]);
		if(yin1<0)yin1 += modn;
		yin1 %= modn;
	}
	for (ll i = 0; i<shang; i++)
	{
		yin2 += quick(a, cha - k*i)*quick(b, k*i) % modn;
	}
	if (shang == 1)ans = yin1% modn;
	else ans = (yin1*yin2) % modn;
	while (ans < 0)
	{
		ans += modn;
		ans %= modn;
	}
	cout << ans;
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    ll GCD=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*y;
    return GCD;
}

ll ni(ll a,ll mod)//扩展欧几里得求逆元
{
    ll x,y;
    ll d=exgcd(a,mod,x,y);
    if(d==1) return (x%mod+mod)%mod;
    return -1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
long long ok(long long x){
    if(x>=0) return x;
    x %= p;
    x+=p;
    return x;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ak%p*b%p;
        // cout << ss<<endl;
    }
    // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    long long cc = bk*nak%p;
    long long zz = (n+1)/k;
   // printf("%lld %lld %lld\n",t,cc,zz);
    if(cc==1){
        ans = t*zz%p;
    }
    else {ans = (1-mi(cc,zz))*ni(1-cc,p)%p;
        if(ans<0) ans+=p;
        ans = ans*t%p;
    }

    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    ll GCD=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*y;
    return GCD;
}

ll ni(ll a,ll mod)//扩展欧几里得求逆元
{
    ll x,y;
    ll d=exgcd(a,mod,x,y);
    if(d==1) return (x%mod+mod)%mod;
    return -1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
long long ok(long long x){
    if(x>=0) return x;
    x %= p;
    x+=p;
    return x;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ak%p*b%p;
        // cout << ss<<endl;
    }
    // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    long long cc = bk*nak%p;
    long long zz = (n+1)/k;
    // printf("%lld %lld %lld\n",t,cc,zz);
    ans = t*ok(1-mi(cc,zz))%p*ni(ok(1-cc),p)%p;
    if(cc==1){
        ans = t*zz%p;
    }

    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    ll GCD=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*y;
    return GCD;
}

ll ni(ll a,ll mod)//扩展欧几里得求逆元
{
    ll x,y;
    ll d=exgcd(a,mod,x,y);
    if(d==1) return (x%mod+mod)%mod;
    return -1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
long long ok(long long x){
    if(x>=0) return x;
    x %= p;
    x+=p;
    return x;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ak%p*b%p;
        // cout << ss<<endl;
    }
    // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    long long cc = bk*nak%p;
    long long zz = (n+1)/k;
   // printf("%lld %lld %lld\n",t,cc,zz);
    ans = t*(1-mi(cc,zz))%p*ni(1-cc,p)%p;
    if(ans<0) ans+=p;

    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    ll GCD=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*y;
    return GCD;
}

ll ni(ll a,ll mod)//扩展欧几里得求逆元
{
    ll x,y;
    ll d=exgcd(a,mod,x,y);
    if(d==1) return (x%mod+mod)%mod;
    return -1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ak%p*b%p;
       // cout << ss<<endl;
    }
   // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    for(int i=0;i<(n+1)/k;i++){
        ans = (ans+t)%p;
        t = t*bk%p*nak%p;
    }
    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

void extgcd(ll a,ll b,ll& d,ll& x,ll& y){
    if(!b){ d=a; x=1; y=0;}
    else{ extgcd(b,a%b,d,y,x); y-=x*(a/b); }
}
ll ni(ll a,ll n){
    ll d,x,y;
    extgcd(a,n,d,x,y);
    return d==1?(x+n)%n:-1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
int main(){
    cin >> n >> a >> b >> k;
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ak%p*b%p;
       // cout << ss<<endl;
    }
   // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    for(int i=0;i<(n+1)/k;i++){
        //if(s[i]=='+'){
            ans = (ans+t)%p;
       // }
       //// else{
       //     ans = (ans+p-t)%p;
       // }
        t = t*bk%p*nak%p;
    }
    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    ll GCD=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*y;
    return GCD;
}

ll ni(ll a,ll mod)//扩展欧几里得求逆元
{
    ll x,y;
    ll d=exgcd(a,mod,x,y);
    if(d==1) return (x%mod+mod)%mod;
    return -1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
long long ok(long long x){
    if(x>=0) return x;
    x %= p;
    x+=p;
    return x;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ak%p*b%p;
        // cout << ss<<endl;
    }
    // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    long long cc = bk*nak%p;
    long long zz = (n+1)/k;
   // printf("%lld %lld %lld\n",t,cc,zz);
    ans = (1-mi(cc,zz))*ni(1-cc,p)%p;
    if(ans<0) ans+=p;
    ans = ans*t%p;

    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    ll GCD=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*y;
    return GCD;
}

ll ni(ll a,ll mod)//扩展欧几里得求逆元
{
    ll x,y;
    ll d=exgcd(a,mod,x,y);
    if(d==1) return (x%mod+mod)%mod;
    return -1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
long long ok(long long x){
    if(x>=0) return x;
    x %= p;
    x+=p;
    return x;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ak%p*b%p;
        // cout << ss<<endl;
    }
    // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    long long cc = bk*nak%p;
    long long zz = (n+1)/k;
   // printf("%lld %lld %lld\n",t,cc,zz);
    ans = t*(1-mi(cc,zz))*ni(1-cc,p)%p;
    if(ans<0) ans+=p;

    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    ll GCD=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*y;
    return GCD;
}

ll ni(ll a,ll mod)//扩展欧几里得求逆元
{
    ll x,y;
    ll d=exgcd(a,mod,x,y);
    if(d==1) return (x%mod+mod)%mod;
    return -1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
long long ok(long long x){
    if(x>=0) return x;
    x %= p;
    x+=p;
    return x;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ak%p*b%p;
        // cout << ss<<endl;
    }
    // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    long long cc = bk*nak%p;
    long long zz = (n+1)/k;
   // printf("%lld %lld %lld\n",t,cc,zz);
    ans = t*ok(1-mi(cc,zz))%p*ni(ok(1-cc),p)%p;

    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

ll pow_mod(ll a, ll b, ll p)   //用到快速幂的知识，函数返回a的b次方对p取模
{
    ll ret = 1;
    while(b)
    {
        if(b & 1)
            ret = (ret * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return ret;
}
ll ni(ll a, ll p)          //返回a对p的逆元
{
    return pow_mod(a, p-2, p);
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss);if(t>=p) t%=p;
        }
        else{
            t = (t+p-ss);if(t>=p) t%=p;
        }
        ss = ss*ak;
        if(ss>=p) ss%=p;
        ss*=b;
        if(ss>=p) ss%=p;
       // cout << ss<<endl;
    }
   // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    for(int i=0;i<(n+1)/k;i++){
        ans = (ans+t);
        if(ans>=p) ans%=p;
        t = t*bk;
        if(t>=p) t%=p;
        t*=nak;
        if(t>=p) t%=p;
    }
    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

void extgcd(ll a,ll b,ll& d,ll& x,ll& y){
    if(!b){ d=a; x=1; y=0;}
    else{ extgcd(b,a%b,d,y,x); y-=x*(a/b); }
}
ll ni(ll a,ll n){
    ll d,x,y;
    extgcd(a,n,d,x,y);
    return d==1?(x+n)%n:-1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
int main(){
    cin >> n >> a >> b >> k;
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ni(a,p)%p*b%p;
       // cout << ss<<endl;
    }
   // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    for(int i=0;i<(n+1)/k;i++){
        //if(s[i]=='+'){
            ans = (ans+t)%p;
       // }
       //// else{
       //     ans = (ans+p-t)%p;
       // }
        t = t*bk%p*nak%p;
    }
    cout << ans;

    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <stack>
#include <vector>
#include <complex>
#include <set>
#include <queue>
#include <utility>
#include <map>
#include <list>
using namespace std;

typedef  long long ll;
const ll maxn = 101000;
const ll p = 1e9+9;

ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(!b)
    {
        x=1;
        y=0;
        return a;
    }
    ll GCD=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*y;
    return GCD;
}

ll ni(ll a,ll mod)//扩展欧几里得求逆元
{
    ll x,y;
    ll d=exgcd(a,mod,x,y);
    if(d==1) return (x%mod+mod)%mod;
    return -1;
}

ll n,a,b,k;
char s[maxn];
ll mi(ll x,ll k){
    if(k==0) return 1;
    ll temp = mi(x,k/2);
    if(k%2==0)
        return temp*temp%p;
    else
        return temp*temp%p*x%p;
}
long long ok(long long x){
    if(x>=0) return x;
    x %= p;
    x+=p;
    return x;
}
int main(){
    scanf("%lld%lld%lld%lld",&n,&a,&b,&k);
    scanf("%s",s);
    ll ans = 0;
    ll t = 0;
    ll ss = mi(a,n);
    ll ak = ni(a,p);
    //cout << ss<<endl;;
    for(int i=0;i<k;i++){
        if(s[i]=='+'){
            t = (t+ss)%p;
        }
        else{
            t = (t+p-ss)%p;
        }
        ss = ss*ak%p*b%p;
        // cout << ss<<endl;
    }
    // cout << t<<endl;
    long long bk = mi(b,k);
    long long nak = ni(mi(a,k),p);
    long long cc = bk*nak%p;
    long long zz = (n+1)/k;
   // printf("%lld %lld %lld\n",t,cc,zz);
    ans = t*ok(1-mi(cc,zz))%p*ni(1-cc,p)%p;

    cout << ans;

    return 0;
}