#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
using namespace std; 
int main(){
  char x[52];
  for(int i='a';i<='z';i++){
    x[i-'a']=i;
  }
  for(int i='A';i<='Z';i++){
    x[26+i-'A']=i;
  }

int n;
  while(cin>>n,n!=0){
    int k[n];
    string s;
    for(int i=0;i<n;i++){
      cin>>k[i];
    }
    cin>>s;
    for(int i=0;i<s.size();i++){
      int b=distance(x,find(x,x+52,s[i])); 
      int c=(b-k[i%n]+52)%52;
      cout<<x[c];
    }
    cout<<endl;
  }
  return 0;
}
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int dp[3][100010];

int main(){

    rep(i,3){
        rep(j,100010){
            dp[i][j] = 0;
        }
    }

    int n;
    int tmp ;
    ll ans = 1;
    ll mod = 1e9+7;
    
    cin >> n;
    vector<int> vec(n);
    rep(j,n){
        cin >> tmp;
        vec[j] = tmp;
        rep(i,3){
            dp[i][j+1] = dp[i][j];
        }
        rep(i,3){
            if(dp[i][j+1] == tmp) {
                dp[i][j+1] = tmp+1;
                break;
            }
        }
    }
    
    rep(j,n){
        ll cnt = 0;
        rep(i, 3){
            if(dp[i][j] == vec[j]){
                cnt++;
            }
        }
        ans = (ans*cnt) % mod;
    }

    cout << ans << endl;
    return 0;
}