#include <iostream>
using namespace std;

int main(){
	int a=0,b=0;
	int na,nb;
	int nc;
	while(1){
	cin>>nc;
	if(nc==0) break;
	a=b=0;
	for(int i=0;i<nc;i++){
		cin>>na>>nb;
		if(na>nb) a+=(na+nb);
		else if(na<nb) b+=(na+nb);
		else {a+=na;b+=nb;}
	}
	cout<<a<<" "<<b<<endl;
	}
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

string station = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int n;
int main() {
    while(cin>>n) {
        if(n==0) return 0;
        vector<int> vec(n);
        rep(i,n) {
            int a; cin>>a;
            vec[i]=a;
        }
        string ss;
        cin>>ss;
        rep(i,ss.size()) {
            int a = i % vec.size();
            int t = station.find(ss[i])-vec[a];
            if(t<0) t += station.size();
            t %= station.size();
            cout<<station[t];
        }
        cout<<endl;

    }

    return 0;
}