#include <iostream>
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

using namespace std;

int main(){
	int n;
	string s;
	string alp = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string ans;
	while(1){
		cin >> n;
		if(n == 0) break;
		int k[n];
		for(int i = 0; i < n; i++){
			cin >> k[i];
		}
		cin >> s;
		for(int i = 0; i < s.length(); i++){
			int kn = i%ARRAY_LENGTH(k);
			int alpn = alp.find(s[i])-k[kn];
			if(alpn < 0) alpn += 52;
			else if(alpn > 52) alpn -=52;
			cout << alp[alpn];
		}
		cout << endl;
	}
}
#include<iostream>

using namespace std;

int dfs(int n, int dan){

	if(dan == n){
		return 1;
	}
	else if(dan > n){
		return 0;
	}
	else{
		int count = 0;
		count = count + dfs(n, dan + 1);
		count = count + dfs(n, dan + 2);
		count = count + dfs(n, dan + 3);
		return count;
	}
}

int main(){
	
	int n;

	while(1){
		cin>>n;

		if(n == 0) break;

		cout<<dfs(n,0) / 10 / 365 + 1<<endl;
	}
}