#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 123455, LG = 60;
ll n, m, k, A[N], P[N], R[LG][N];
int main()
{
    scanf("%lld", &n);
    for (int i = 0; i < n; i++)
        scanf("%lld", &A[i]), P[i] = i;
    scanf("%lld%lld", &m, &k);
    for (int i = 0; i < m; i++)
    {
        int a;
        scanf("%lld", &a);
        swap(P[a], P[a - 1]);
    }
    for (int i = 0; i < n; i++)
        R[0][i] = P[i];
    for (int j = 1; j < LG; j++)
        for (int i = 0; i < n; i++)
            R[j][i] = R[j - 1][R[j - 1][i]];
    printf("%lld\n", A[0]); ll nw = A[0];
    for (int i = 1; i < n; i++)
    {
        int id = i;
        for (int j = 0; j < LG; j++)
            if ((k >> j) & 1LL)
                id = R[j][id];
        nw += A[id] - A[id - 1];
        printf("%lld\n", nw);
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) (a).begin(), (a).end()
#define pw(x) (1ll<<(x))
#define lb(x) ((x) & -(x))
#define endl "\n"
#define FI(x) freopen(#x".in","r",stdin)
#define FO(x) freopen(#x".out","w",stdout)
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
//typedef uniform_int_distribution<ll> RR;
const int P = 1e9 + 7;
//ll rnd(ll l, ll r) { mt19937 gen(rand()); RR dis(l, r); return dis(gen); }
int add(int a, int b) {if((a += b) >= P) a -= P; return a < 0 ? a + P : a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----
const int N = 1e5 + 7;
ll n, m, p[N], b[N], a[N], ans[N], now, vis[N], pp[N];
ll k;
int main(){
	//FI(a);
	ios::sync_with_stdio(0);
	cin.tie(0);
	//cout << setiosflags(ios::fixed);
	//cout << setprecision(2);
	cin >> n;
	rep(i, 1, n+1) cin >> a[i];
	per(i, 1, n+1) a[i] -= a[i-1];
//	rep(i, 1, n+1) de(a[i]);
	cin >> m >> k;
	rep(i, 1, m+1) cin >> b[i];
	rep(i, 1, n + 1) p[i] = i;
	rep(i, 1, m + 1) swap(p[b[i]], p[b[i]+1]);
	rep(i, 1, n+1) pp[p[i]] = i;
	rep(i, 1, n+1) p[i] = pp[i];
//	rep(i, 1, n+1) de(p[i]);
	rep(i, 1, n+1) if (!vis[i]){
		now = i;
		vi tmp;
		while (1) {
			vis[now] = 1;
			tmp.pb(now);
			now = p[now];
			if (now == i) break;
		}
		//de(sz(tmp));
		rep(i, 0, sz(tmp)) {
			int u = (i + k) % sz(tmp);
			//de(tmp[u]);
			ans[tmp[u]] = a[tmp[i]];
		}
	}
	//rep(i, 1, n+1) de(ans[i]);
	//de(a[1]);
	rep(i, 1, n+1) ans[i] += ans[i-1], cout << ans[i] << endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...)
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
const int N=2020;
int a[N][N],el[N][N],eu[N][N],p[N][N];
int32_t main(){
    int n,m,q;
    cin>>n>>m>>q;
    for(int i=1;i<=n;++i){
        string s;cin>>s;s="#"+s;
        for(int j=1;j<=m;++j){
            a[i][j]=s[j]-'0';
            int pl=a[i][j]&a[i][j-1];
            int pu=a[i][j]&a[i-1][j];
            p[i][j]=p[i-1][j]+p[i][j-1]-p[i-1][j-1]+a[i][j];
            el[i][j]=el[i-1][j]+el[i][j-1]-el[i-1][j-1]+pl;
            eu[i][j]=eu[i-1][j]+eu[i][j-1]-eu[i-1][j-1]+pu;
        }
    }
    while(q--){
        int x1,y1,x2,y2;
        cin>>x1>>y1>>x2>>y2;
        int v=p[x2][y2]-p[x2][y1-1]-p[x1-1][y2]+p[x1-1][y1-1];
        int e=el[x2][y2]-el[x2][y1]-el[x1-1][y2]+el[x1-1][y1]+
            eu[x2][y2]-eu[x2][y1-1]-eu[x1][y2]+eu[x1][y1-1];
        cout<<v-e<<'\n';
    }
    return 0;
}


#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    repk(i, n, 1000) {
        string s = to_string(i);
        if (s[0] == s[1] && s[0] == s[2]) {
            cout << s << endl;
            return 0;
        }
    }
}

#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){

    int R;
    cin >> R;
    double ans = (2 * R) * acos(-1.0);

    cout << setprecision(20) << ans << endl;

}


#include<bits/stdc++.h>
using namespace std;

int main(){

  long long x;
  cin>>x;

  if(x/11==0){
    if(x>6){
      cout<<2<<endl;
    }else{
      cout<<1<<endl;
    }
    return 0;
  }else{

    if(x%11==0){
      cout<<x/11*2<<endl;
    }else if((x-x/11*11)>6){
      cout<<x/11*2+2<<endl;
    }else{
      cout<<x/11*2+1<<endl;
    }
  }
  return 0;
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;

int main() {
	long long x;
	cin >> x;
	long long ans = 0;

	if (x % 11 == 0) {
		ans = x / 11 * 2;
	}
	else if(x % 11 <= 6) {
		ans = x / 11 * 2 + 1;
	}
	else {
		ans = x / 11 * 2 + 2;
	}

	cout << ans << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <list>
#include <set>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>

using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
using pii=pair<int,int>;
using vs=vector<string>;
using vpii=vector<pii>;
using si=set<int>;

#define REP(i,a) for(int i=0;i<a;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rREP(i,a) for(int i=(a)-1;i>=0;i--)
#define rFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define out(S) cout<<(S)<<endl;
#define beginend(v) (v).begin(),(v).end()
#define IfOut(condition,text) if(condition){out(text);return 0;}
#define IfOutElse(condition,if_text,else_text) if(condition){out(if_text);return 0;}else{out(else_text);return 0;}
#define mod(s) ((s)%(ll)(1e9+7))
ll modpow(ll i, ll j) { ll tmp = 1; while (j) { if (j % 2)tmp = mod(tmp*i); i = mod(i*i); j /= 2; }return tmp; }
#define divmod(a,b) (mod(a*modpow((ll)b,(ll)(1e9+5))))
#define pb(i) push_back(i)
#define fst first
#define snd second
#define Foreach(item,collection) for(auto item:collection)
#define INF 1e10
#define removeAll(vec,deleg) auto itr=remove_if(beginend(vec),deleg);vec.erase(itr,vec.end());
void removeAt(string& s, int index) { s.erase(index, 1); }
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }
ll manhattanDistance(ll x1, ll y1, ll x2, ll y2) { return (abs(x2 - x1) + abs(y2 - y1)); }
vector<ll> sieveOfEratosthenes(int max) {ll prime;double sqrtmax = sqrt(max);vector<ll> primeVec, searchVec;FOR(i, 2, max + 1) searchVec.push_back(i);do{prime = searchVec[0];primeVec.push_back(prime);auto itr = remove_if(beginend(searchVec), [=](ll x)->bool {return x%prime == 0; });searchVec.erase(itr, searchVec.end());} while (prime < sqrtmax);primeVec.reserve(primeVec.size() + searchVec.size());primeVec.insert(primeVec.end(), beginend(searchVec));return primeVec;}
ll sum(vi v) {ll sum=0;Foreach(i,v){sum+=i;}return sum;}
#define ShowAll(v) Foreach(i,v) out(i);

int shouhi(int v,int x,int y){
    double motone=(double)v*100.0/(100.0+x);
    return motone*(100.0+y)/100.0;
}

int main(){
    vi ans;
    int m,nmin,nmax;
    while (cin>>m>>nmin>>nmax,(m||nmin||nmax))
    {
        vi P(m);
        REP(i,m)cin>>P[i];
        int n=nmin-1,pmax=0;
        FOR(i,nmin-1,nmax){
            if(pmax<=P[i]-P[i+1]){
                pmax=P[i]-P[i+1];
                n=i;
            }
        }
        ans.pb(n+1);
    }

    ShowAll(ans);
    return 0;
}

#include <iostream>

using namespace std;

int main(void){
  while(1){
    int m, nmin, nmax;
    cin >> m;
    cin >> nmin;
    cin >> nmax;
    if(m == 0 && nmin == 0 && nmax == 0){ return 0; }

    int P[m];

    for(int i = 0 ; i < m ; i++){
      cin >> P[i];
    }

    int ans = nmin;
    int max = -1;
    for(int i = nmin ; i <= nmax ; i++){
      if(max >= P[i] - P[i - 1]){
        max = P[i] - P[i - 1];
        ans = i;
      }
    }

    cout << ans << endl;
  }

  return 0;
}


#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main() {
  int n,m;
  cin >> n >> m;
  int l[m],r[m];

  for(int i = 0; i < m; i++) {
    cin >> l[i] >> r[i];
  }

  int ans = *max_element(l,l+m) - *min_element(r,r+m);
  if(ans > 0) {
    cout << 0 << endl;
  }else {
    cout << abs(ans)+1 << endl;
  }
  return 0;
}

#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <stack>
#include <string>
#include <vector>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;

int main()
{
    int n,m;
    cin >> n >> m;
    int max = 0,min = 1e9;
    vector<vector<int>> G(m,vector<int>(2));
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < 2; j++)
        {
            cin >> G[i][j];
        }
        if (max < G[i][0])
        {
            max = G[i][0];
        }
        if (min > G[i][1])
        {
            min = G[i][1];
        }
    }
    if (max > min)
    {
        cout << "0" << endl;
    }else{
        cout << min-max+1 << endl;
    }
}


#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int main(){
    ll X, Y;
    cin >> X >> Y;
    ll cnt = LINF;
    rep(i, 2) rep(j, 2){
        ll x = X, y = Y;
        ll tmp = 0;
        if (i) x *= -1, tmp++;
        if (j) y *= -1, tmp++;
        if (x <= y) {
            tmp += y - x;
            cnt = min(cnt, tmp);
        }
    }

    cout << cnt << endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
   long x,y;
   cin >> x >> y;
   if(x==y) cout << 0 << endl;
   else if(y-x==1||y==-x) cout << 1 << endl;
   else cout << min({abs(x-y),abs(x+y-1),abs(x+y+1),abs(x-y+2)})+2 << endl;
}


#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;

ll INF = 1LL << 60;

vector<vector<char>> vec;
vector<pair<int, int>> direct = {{1,0},{-1, 0}, {0,1}, {0, -1}};
vector<vector<int>> dist;
queue<pair<int, int>> que;
int H, W;

int
bfs()
{

  while(!que.empty()){
    int x = que.front().first;
    int y = que.front().second;
    que.pop();
    rep(i, 0, 4){
      int dx = x + direct[i].first;
      int dy = y + direct[i].second;
      if(dx < 0 || dx >= H || dy < 0 || dy >= W) continue;
      if(vec[dx][dy] == '#') continue;
      if(dist[dx][dy] == -1){
        dist[dx][dy] = 1 + dist[x][y];
        que.push({dx, dy});
      }
    }
  }

  int ans = 0;
  rep(i, 0,H){
    rep(k, 0, W){
      ans = max(ans, dist[i][k]);
    }
  }
  return ans;
}

int
main() {

  cin >> H >> W;
  vec.resize(H);
  dist.resize(H, vector<int>(W, -1));
  rep(i, 0, H){
    rep(k, 0, W){
      char c; cin >> c;
      vec[i].push_back(c);
      if(vec[i][k] == '#') dist[i][k] = 0, que.push({i, k});
    }
  }

  int ans = bfs();

  cout << ans << endl;

}

#include <iostream>
#include <vector>
using namespace std;

int main(){
    int n, t0;
    cin >> n >> t0;
    vector<int> t(n);
    for(int i = 0; i < n; i++) cin >> t[i];

    long long int ans = t0;

    for(int i = 1; i < n; i++){
        if(t[i]-t[i-1] >= t0) ans += t0;
        else ans += t[i]-t[i-1];
    }

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


#include<bits/stdc++.h>
using namespace std;

#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)

using ll = long long;
using pii = pair<int, int>;
using Vi = vector<int>;

int main() {
  int N,K;
  cin >> N >> K;
  if(N%K==0){
    cout << 0 << endl;
  }
  else{
    cout << 1 << endl;
  }

}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
    int N, K; cin >> N >> K;
    cout << (N + K - 1) / K - N / K << endl;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 600000

int main() {
	int n, k;
	scanf("%d", &n);
	printf("%d\n", n*n*n);

	return 0;
}

#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a;
	for(int i=3;i<=a;i++){
		b=0;
		if(i%3==0 || i%10==3){
			cout<<" "<<i;
			b=1;
		}
		if(i>=30 && b==0){
			for(int j=i;j>=9;){
			j=j/10;
			if(j%10==3){
				cout<<" "<<i;
				break;
				}
			}
		}
	}
	cout<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int main(){
	ios::sync_with_stdio(false);
	int n;string s;
	cin>>n>>s;
	int num=0;
	long long ans=1;
	for(int i=1;i<=n;++i) ans=ans*i%mod;
	for(int i=0;i<2*n;++i){
		if((s[i]=='W')^num&1) ans=ans*num%mod,num--;
		else num++;
	}
	printf("%lld\n",num?0:ans);
}

#include <cassert>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"

#define rep(i, a, b) for (long long (i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}

template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;

  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }

  long long x = 1;

  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P = std::pair<long long, long long>;

ll gcd(ll a,ll b){
  if(a%b==0)return b;
  return gcd(b,a%b);
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll n;
  std::cin>>n;

  std::vector<long double> a(n);
  rep(i,0,n)std::cin>>a[i];

  long double sum=0;

  rep(i,0,n)sum+=a[i];

  sum/=(long double)n;

  long double min=1e9;

  rep(i,0,n)chmin(min,std::abs(a[i]-sum));

  rep(i,0,n){
    if(std::abs(a[i]-sum)==min){
      std::cout<<i<<"\n";
      return 0;
    }
  }

  return 0;
}


#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int N, M;
    cin>>N>>M;

    vector<vector<long long>> T(3*N, vector<long long>(6*N+1));
    T[0][3*N+1] = 1;
    T[1][3*N-1] = 1;
    T[2][3*N] = 2;
    for (int i=0; i<3*N; i++)
        for (int j=0; j<=6*N; j++)
            if (T[i][j]>0)
                for (int k=1; k<=3; k++)
                    if (i+k<3*N)
                    {
                        long long c = 1;
                        for (int l=0; l<k-1; l++)
                            c *= i+l+2;
                        int d = int(k==1) - int(k==2);
                        T[i+k][j+d] += c*T[i][j];
                        T[i+k][j+d] %= M;
                    }
    long long ans = 0;
    for (int i=3*N; i<=6*N; i++)
    {
        ans += T[3*N-1][i];
        ans %= M;
    }
    cout<<ans<<endl;
}

#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
#define makefast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define comp(x) (lower_bound(vec.begin(), vec.end(), x) - vec.begin())
#define lc (v * 2)
#define rc (v * 2 + 1)
long long M = 1e9 + 7;
//>>>>>>>>>>>>>>>>>>>

#define int long long

const int N = 1e6 + 7;

int n;

int pw(int a, int b) {
	int res = 1;
	while (b) {
		if (b % 2)
			res = (res * a) % M;
		b /= 2;
		a = (a * a) % M;
	}
	return res;
}
int f[N], rf[N];
int chs(int a, int b) {
	if (a > b)
		return 0;
	if (a < 0 || b < 0 || a >= N || b >= N) {
		cout << "FITA";
		exit(0);
	}
	return (((f[b] * rf[a]) % M) * rf[b - a]) % M;
}
int sm3[N], sm2[N];
int32_t main() {
	makefast;
	cin >> n >> M;
	f[0] = rf[0] = 1;
	for (int i = 1; i < N; i++) {
		f[i] = (f[i - 1] * i) % M;
		rf[i] = (rf[i - 1] * pw(i, M - 2)) % M;
	}
	sm3[0] = 1;
	for (int i = 1; i < 10000; i++)
		sm3[i] = (((sm3[i - 1] * chs(3, 3 * i)) % M) * pw(i, M - 2)) % M;
	sm2[n + 1] = 1;
	for (int i = n; i >= 0; i--)
		sm2[i] = (((sm2[i + 1] * chs(2, 3 * n - 2 * (n - i))) % M) * pw(n - i + 1, M - 2)) % M;
	int res = 0;
	for (int b = 0; b <= n; b++)
		for (int a = b; a + 2 * b <= 3 * n; a++) {
			if ((a + 2 * b) % 3)
				continue;
			int c = (3 * n - (a + 2 * b)) / 3;
			int t = sm2[n - b + 1];
			t = (t * chs(a, 3 * n - 2 * b)) % M;
			t = (t * ((sm3[c] * pw(2, c)) % M)) % M;
			res = (t + res) % M;
		//	cout << a << " " << b << " " << c << " > " << t << " sm2 : " << sm2[n - b + 1] << " chs : " << chs(a, 3 * n - 2 * b) << " sm3 : " << sm3[c] << endl;
		}
	cout << res;
	return 0;
}


#include<iostream>
#include<math.h>
#include<algorithm>
#include<stdint.h>
#include<vector>
#include<deque>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include<time.h>
#include<array>
#include<iomanip>
#include<list>
#include<set>
#include<map>
#include<random>
#include<unordered_map>
#include<unordered_set>
#include<bitset>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;

//BDD,ZDD,kdtree, bdtree,bicalc, bolonoy, doloney, tree, chinesemod,segmenttree,daikusutora, saidairyuu, 2bugurahu, heirokenshutu, topologicalsort, kyourenketuseibun

#define REP(i,a,b) for(int i = a; i < b; ++i)
#define PRI(s) cout << s << endl
#define PRIY PRI("Yes")
#define PRIN PRI("No")

using b = bitset<6400 * 2 + 64>;

int main() {
	ll H, W;
	vector<vector<b>> f;
	vector<vector<ll>> a, b;
	cin >> H >> W;
	f.resize(H);
	a.resize(H);
	b.resize(H);
	REP(i, 0, H) {
		f[i].resize(W);
		a[i].resize(W);
		REP(j, 0, W) {
			f[i][j].reset();
			cin >> a[i][j];
		}
	}
	REP(i, 0, H) {
		b[i].resize(W);
		REP(j, 0, W) {
			cin >> b[i][j];
		}
	}
	int i0 = 6400;
	f[0][0][i0 + b[0][0] - a[0][0]] = true;
	f[0][0][i0 - b[0][0] + a[0][0]] = true;
	auto bs = [](auto& b, int d) {
		if (d >= 0) return b << d;
		else return b >> -d;
	};
	REP(j, 1, W) f[0][j] = bs(f[0][j - 1], b[0][j] - a[0][j]) | bs(f[0][j - 1], -b[0][j] + a[0][j]);
	REP(i, 1, H) f[i][0] = bs(f[i - 1][0], b[i][0] - a[i][0]) | bs(f[i - 1][0], -b[i][0] + a[i][0]);
	REP(i, 1, H)REP(j, 1, W) {
		f[i][j] = bs(f[i][j - 1], b[i][j] - a[i][j]) | bs(f[i - 1][j], b[i][j] - a[i][j]);
		f[i][j] |= bs(f[i][j - 1], -b[i][j] + a[i][j]) | bs(f[i - 1][j], -b[i][j] + a[i][j]);
	}
	for (int i = 0; i <= 6400; ++i) {
		if (f[H - 1][W - 1][i0 + i] || f[H - 1][W - 1][i0 - i]) {
			PRI(i);
			return 0;
		}
	}
	return 0;
}

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
#include <unordered_set>

#define YesNo(b) ((b) ? "Yes" : "No")
#define YESNO(b) ((b) ? "YES" : "NO")

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;

template<template<class...> class ContT, class ValueT, size_t Dim>
struct vec_type
{
    using type = ContT<typename vec_type<ContT, ValueT, Dim-1>::type>;
};

template<template<class...> class ContT, class ValueT>
struct vec_type<ContT, ValueT, 0>
{
    using type = ValueT;
};

template<class ValueT, size_t Dim>
using vec_t = typename vec_type<std::vector, ValueT, Dim>::type;

template<class ValueT, size_t Dim, class = typename std::enable_if<Dim == 0>::type>
auto make_vec(ValueT value = ValueT()) -> ValueT
{
    return value;
}

template<class ValueT, size_t Dim, class... Rest>
auto make_vec(size_t size0, Rest... rest)
{
    auto vec = make_vec<ValueT, Dim-1>(rest...);
    return std::vector(size0, vec);
}

int diffabs(int l, int r)
{
    if (l < r) return r-l;
    else return l-r;
}

int iabs(int i)
{
    if (i > 0) return i;
    else return -i;
}

int main()
{
    int H, W;
    cin >> H >> W;

    vec_t<int,2> A = make_vec<int,2>(H, W);
    vec_t<int,2> B = make_vec<int,2>(H, W);

    for (int h = 0; h < H; ++h)
        for (int w = 0; w < W; ++w)
            cin >> A[h][w];

    for (int h = 0; h < H; ++h)
        for (int w = 0; w < W; ++w)
            cin >> B[h][w];

    vec_t<bool,3> dp = make_vec<bool,3>(H, W, (H+W)*80, false);

    for (int h = 0; h < H; ++h)
    {
        for (int w = 0; w < W; ++w)
        {
            int d = diffabs(A[h][w], B[h][w]);
            if (h == 0 && w == 0)
            {
                dp[h][w][d] = true;
            }

            if (w > 0)
            {
                for (size_t i = 0; i < dp[h][w-1].size(); ++i)
                {
                    if (dp[h][w-1][i])
                    {
                        dp[h][w][i+d] = true;
                        dp[h][w][iabs(i-d)] = true;
                    }
                }
            }

            if (h > 0)
            {
                for (size_t i = 0; i < dp[h-1][w].size(); ++i)
                {
                    if (dp[h-1][w][i])
                    {
                        dp[h][w][i+d] = true;
                        dp[h][w][iabs(i-d)] = true;
                    }
                }
            }
        }
    }

    const auto &hw = dp[H-1][W-1];
    auto it = find_if(begin(hw), end(hw), [](auto b){ return b; });
    int ans = std::distance(begin(hw), it);
    cout << ans << endl;
}


#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,y;
	int i,j,flg=0;
	scanf("%d %d",&n,&y);
	for(i=0;i<=n;i++){
		for(j=0;j<=n;j++){
			if(n-(i+j)<0) {
				break;
			}
			if(i+j+n-(i+j)==n&&y==i*10000+j*5000+(n-(i+j))*1000){
				flg=1;
				break;
			}
		}
		if(flg==1) break;
	}
	if(flg==1){
		printf("%d %d %d\n",i,j,n-(i+j));
	}
	else if(flg==0||flg==2){
		printf("-1 -1 -1\n");
	}
	return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int N, Y;
  cin >> N >> Y;

  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= N; y++) {
      if (N - x - y < 0) continue;
      int sum = 10000 * x + 5000 * y + 1000 * (N - x - y);
      if (sum == Y){
        cout << x << " " << y << " " << N - x - y << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}


#include<bits/stdc++.h>

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD ((ll)1e9+7)
ll N,S;
vector<pll> xpv[2];
ll i, j, k,ans;
bool ck(ll t,ll aa,ll bb){
    return t ? (aa <= bb) : (aa < bb);
}
int main(){
    //printf("%lld\n", MOD);
    scanf("%lld%lld", &N,&S);
    fornum(i,0,N){
        ll x, p;
        scanf("%lld%lld", &x, &p);
        xpv[S < x].push_back(mp(abs(x - S), p));
    }
    sort(xpv[0].begin(), xpv[0].end(), greater<pll>());
    sort(xpv[1].begin(), xpv[1].end(), greater<pll>());
    if(xpv[0].size()*xpv[1].size()==0){
        printf("%lld",xpv[0].size()?xpv[0][0].first:xpv[1][0].first);
        return 0;
    }

    ll n = 0, t = 0;
    ll ii[]={0,0};
    n= xpv[0][0].second+xpv[1][0].second;
    if(xpv[0][0].second<xpv[1][0].second){
        t = 0;
    }else{
        t = 1;
    }
    ii[t]++;
    ans += xpv[t][0].first + xpv[!t][0].first * 2;
    //printf("%lld,%lld\n", xpv[t][0].second, xpv[!t][0].second);
    while(true){
        while(ii[t]<xpv[t].size()&&ck(t,xpv[t][ii[t]].second,n)){
            //printf("%lld,%lld\n", xpv[t][ii[t]].second, n);
            n += xpv[t][ii[t]].second;
            ii[t]++;
        }
        //printf("%lld,%lld,%lld\n", t, ii[t],n);
        if(ii[t]==xpv[t].size())
            break;
        n += xpv[t][ii[t]].second;
        ans += xpv[t][ii[t]].first*2;
        t = !t;
        ii[t]++;
    }
    printf("%lld", ans);

    return 0;
}

/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  echo -n '  ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim).

 * Solution:
 * 考虑边界，推导结论，子问题递归求解

  如果 S <= p[1] 或者 S >= p[n] ，显然所有人投票都是一个方向，不妨假设 p[1] < S < p[n] 。

  考虑处在最边上的 1 号点和 n 号点，如果 a[1] >= a[n] ，那么一定先到 1 ，否则先到 n 。归
纳证明，如果 n = 2 显然成立，对于 n >= 3 ，若 S >= a[n - 1] 显然成立，否则 S < a[n - 1] ，
此时考虑 1 和 n - 1 ，如果先到 n - 1 就会回到 S >= a[n - 1] 的情况。

  不妨假设 a[1] >= a[n] ，那么到 n 的时间就一定是到 1 的时间加上 1 到 n 的距离，那么 n 想
要最小化到达 n 的时间其实就是等价于最小化到达 1 的时间，可以赋值 a[1] = a[1] + a[n] 并赋
值 n = n - 1 转换为子问题，递归求解，可以求出每个点的到达时间。

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator () (a...); }
} read;

const int maxn = 1000005;
int p[maxn];
ll a[maxn];
ll t[maxn];

void solve (int l, int r, int S) {
	if (S <= p[l]) {
		for (int i = l; i <= r; i ++)
			t[i] = p[i] - S;
		return;
	}
	if (S >= p[r]) {
		for (int i = l; i <= r; i ++)
			t[i] = S - p[i];
		return;
	}
	if (a[l] >= a[r]) {
		a[l] += a[r];
		solve(l, r - 1, S);
		t[r] = t[l] + p[r] - p[l];
	} else {
		a[r] += a[l];
		solve(l + 1, r, S);
		t[l] = t[r] + p[r] - p[l];
	}
}

int main () {
	int n = read, S = read;
	for (int i = 1; i <= n; i ++) read(p[i], a[i]);
	solve(1, n, S);
	ll ans = 0;
	for (int i = 1; i <= n; i ++) ans = std::max(ans, t[i]);
	printf("%lld\n", ans);
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 100000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* global variables */
vector<int> parent(MAX), prenum(MAX), lowest(MAX);
vector< vector<int> > Adj(MAX);
vector<bool> visited(MAX, false);
int N;
int timer;

/* function */
void dfs(int cur, int prev);
void art_points();

/* main */
int main() {
    int m;
    cin >> N >> m;
    for (int i = 0; i < m; i++) {
        int v, u;
        cin >> v >> u;
        Adj[v].push_back(u);
        Adj[u].push_back(v);
    }

    art_points();

}

void dfs(int cur, int prev) {
    // after visited node cur
    prenum[cur] = lowest[cur] = timer;
    timer++;
    visited[cur] = true;

    int next;
    for (int i = 0; i < Adj[cur].size(); i++) {
        next = Adj[cur][i];
        if ( !visited[next] ) {
            // before visiting next node
            parent[next] = cur;
            dfs(next, cur);
            // after visiting next node
            lowest[cur] = min(lowest[cur], lowest[next]);
        }
        else if (next != prev) {
            // Edge(cur, next) is Back-Edge
            lowest[cur] = min(lowest[cur], prenum[next]);
        }
    }
}

void art_points() {
    timer = 1;
    // calculate lowest
    dfs(0, -1); // 0 == root

    set<int> ap;
    int child_of_root = 0;
    for (int i = 1; i < N; i++) {
        int p = parent[i];
        if (p == 0) child_of_root++;
        else if (prenum[p] <= lowest[i]) ap.insert(p);
    }
    if (child_of_root >= 2) ap.insert(0);
    for (auto it = ap.begin(); it != ap.end(); it++) {
        cout << *it << '\n';
    }
}

#include <bits/stdc++.h>

using namespace std;

using i64 = int64_t;

const i64 MOD = 1e9 + 7;

struct LowLink{
    vector<vector<int>>& edges;
    // 関節点
    vector<int> art;
    vector<pair<int,int>> bridge;

    vector<int> used, ord, low;
    int k;

    void dfs(int idx, int par){
        ord[idx] = k++;
        low[idx] = ord[idx];
        bool is_art = false;
        int cnt = 0;
        for(auto& to : edges[idx]){
            if(ord[to] == -1){
                ++cnt;
                dfs(to, idx);
                low[idx] = min(low[idx], low[to]);
                is_art |= par != -1 && low[to] >= ord[idx];
                if(ord[idx] < low[to])
                    bridge.emplace_back(idx, to);
            }else if(to != par)
                low[idx] = min(low[idx], ord[to]);
        }
        is_art |= (par == -1 && cnt > 1);
        if(is_art)
            art.emplace_back(idx);
    }

    LowLink(vector<vector<int>>& edges) :
        edges(edges),
        ord(edges.size(), -1),
        low(edges.size(), 0),
        k(0)
    {
        for(int i = 0; i < edges.size(); ++i)
            if(ord[i] == -1)
                dfs(i, -1);
        for(auto& b : bridge)
            b = make_pair(min(b.first, b.second), max(b.first, b.second));
        sort(art.begin(), art.end());
        sort(bridge.begin(), bridge.end());
    }
};

signed main(){
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v(m);
    vector<vector<int>> edges(n);
    for(int i = 0; i < m; ++i){
        vector<int> l(2);
        for(auto& x : l)
            cin >> x;
        sort(l.begin(), l.end());
        v[i] = make_pair(l.front(), l.back());
        edges[l[0]].emplace_back(l[1]);
        edges[l[1]].emplace_back(l[0]);
    }
    LowLink ll(edges);
    for(auto& x : ll.art)
        cout << x << endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin >>a;
    cout << a * a * a<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
long long mi[233];
long long work(int l,int r,long long dlt)
{
	if ((l>=r)&&(dlt)) return 0;
	if (l==r) return 10-(l==0);
	if (l>r) return 1;
	int t=(10-dlt%10)%10;
	dlt-=t*(mi[r-l]-1);
	return (10-(l==0)-t)*work(l+1,r-1,abs(dlt)/10);
}
int main()
{
	mi[0]=1;for (int i=1;i<=18;i++) mi[i]=mi[i-1]*10;
	int d;scanf("%d",&d);long long ans=0;
	for (int i=0;i<=17;i++) ans+=work(0,i,d);
	cout<<ans+(d==0)<<endl;
}


#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld\n",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
#define mod (int)(1e9 + 7)

using namespace std;
double dp[301][301][301];

double dfs(int a, int b, int c, int N){
	if(a == 0 && b == 0 && c == 0)return 0.0;
	if(dp[a][b][c] > -0.5)return dp[a][b][c];
	double res = 0;
	double ks = (double)N / (a + b + c);
	if(a){
		res += (ks + dfs(a-1,b,c, N)) * (double)(a)/(a + b + c);
	}
	if(b){
		res += (ks + dfs(a+1,b-1,c, N)) * (double)(b)/(a + b + c);
	}
	if(c){
		res += (ks + dfs(a,b+1,c-1, N)) * (double)(c)/ (a + b + c);
	}
	return dp[a][b][c] = res;
}

int main(){
	memset(dp, -1, sizeof(dp));
	int n;
	cin >> n;
	vector<int> a(n);
	cout << fixed << setprecision(15);
	int one = 0;
	int two = 0;
	int three = 0;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(a[i] == 1)one++;
		if(a[i] == 2)two++;
		if(a[i] == 3)three++;
	}
	// dp[i][j][k] = expected no of operations with i 1's , j 2's , k 3's
	double res = dfs(one, two, three, n);
	cout << res << endl;

}

#include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
const int A = 3e2 + 2;
const int mod = 1e9 + 7;
int n;
bool vis[A][A][A];
ld mem[A][A][A];
ld solve (int c1, int c2, int c3) {
    if (c1 + c2 + c3 == 0) return 0;
    if (vis[c1][c2][c3])
        return mem[c1][c2][c3];
    vis[c1][c2][c3] = 1;
    int c0 = n - (c1 + c2 + c3);
    ld ret = 1;
    if (c1)
        ret += solve(c1 - 1, c2, c3) * (c1 / (n * 1.0));
    if (c2)
        ret += solve(c1 + 1, c2 - 1, c3) * (c2 / (n * 1.0));
    if (c3)
        ret += solve(c1, c2 + 1, c3 - 1) * (c3 / (n * 1.0));
    ret /= (1 - (c0 / (n * 1.0)));
    return mem[c1][c2][c3] = ret;
}
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    int freq[4] = {};
    for (int i = 0, x; i < n; i++) {
        cin >> x;
        freq[x]++;
    }
    cout << setprecision(9) << fixed << solve(freq[1], freq[2], freq[3]);
    return 0;
}


#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<list>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int msb32(uint32_t x) { return 31 - __builtin_clz(x); }
int msb(uint64_t x) {
  if(x < (1ULL<<32)) return msb32((uint32_t)x);
  return 32 +msb((uint32_t)(x>>32));
}

struct bit_base {
  uint64_t bases[64];
  bit_base() { std::fill_n(bases, 64, (uint64_t)0); }
  uint64_t add(uint64_t n) {
    int x = msb(n);
    while(bases[x] > 0) {
      n ^= bases[x];
      if(n == 0) return 0;
      x = msb(n);
    }
    return bases[x] = n;
  }
};

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int T; std::cin >> T;
  for(int t = 0; t < T; ++t) {
    int N; std::cin >> N;
    std::vector<uint64_t> A(N);
    for(auto& Ai: A) std::cin >> Ai;
    std::string S; std::cin >> S;
    bit_base b;
    for(int n = N-1; n >= 0; --n) {
      if(S[n] == '0') {
        b.add(A[n]);
      } else {
        if(b.add(A[n]) > 0) { std::cout << "1\n"; break; }
      }
      if(n == 0) { std::cout << "0\n"; break; }
    }
  }
  return 0;
}

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0;
	char c;
	for(c=getchar();!isdigit(c);c=getchar());
	for(;isdigit(c);c=getchar())x=x*10+c-'0';
}

const int N=205,P=1e9+7,L=62;

int mul(int a,int b){ return 1ll*a*b%P; }
//int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
int gcd(int a,int b){ return !b?a:gcd(b,a%b); }

int n,T;
ll a[N],pr[L+2],bk[L+2],ans;
char s[N];
void add(ll *b,ll x){
	dec(i,L,0){
		if((x>>i)&1){
			if(b[i])x^=b[i];
			else {b[i]=x; break; }
		}
	}
}
bool test(ll *b,ll x){
	dec(i,L,0)if((x>>i)&1){
		x^=b[i];
	}
	return x==0;
}
bool equal(ll *b1,ll *b2){
	dec(i,L,0)if(b1[i]){
		if(!test(b2,b1[i]))return false;
	}
	return true;
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("d.in","r",stdin);
#endif
	read(T);
	while(T--){
		read(n);
		rep(i,1,n)read(a[i]);
		scanf("%s",s+1);
		ans=0;
		mem(bk,0);
		dec(i,n,1){
			if(s[i]=='0')add(bk,a[i]);
			else ans|=!test(bk,a[i]);
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;

const int mod = 998244353;

int main() {
    int n, d0;
    cin >> n >> d0;

    if(d0 != 0) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> d(100005);
    d.at(0) = 1;
    int max_d = 0;
    for(int i = 1; i < n; ++i) {
        int di;
        cin >> di;
        max_d = max(max_d, di);
        d.at(di)++;
    }

    if(d.at(0) != 1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 1;
    int i = 1;
    while(i < n) {
        if(d.at(i) == 0) break;
        rep(j, d.at(i)) {
            ans *= d.at(i-1);
            ans %= mod;
        }
        ++i;
    }
    if(i < max_d) cout << 0 << endl;
    else cout << ans << endl;

    return 0;
}

#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll ans[110][110];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	vector<ll>d(n), h(n);
	ll maxh = 0;
	rep(i, n) {
		cin >> d[i];
		if (d[0] != 0) {
			cout << 0 << endl;
			return 0;
		}
		if (i != 0 && d[i] == 0) {
			cout << 0 << endl;
			return 0;
		}
		h[d[i]]++;
		maxh = max(maxh, d[i]);
	}
	ll ans = 1;
	rep(i, maxh) {
		rep(j, h[i + 1]) {
			ans *= h[i];
			ans %= 998244353;
		}
	}
	cout << ans << endl;
	return 0;
}


/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __
.' ____ \ [  |      (_)                [  |
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |,
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/

*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

int n, m;

void warshall_floyd(vvi& d)
{
  REP(k, m) REP(i, m) REP(j, m) {
    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
  }
}

signed main()
{
  while (cin >> n >> m, n || m) {
    vvi dc, dt;
    dc = dt = vvi(m, vi(m, INF));
    REP(i, n) {
      int a = in() - 1, b = in() - 1;
      dc[a][b] = dc[b][a] = in();
      dt[a][b] = dt[b][a] = in();
    }
    warshall_floyd(dc);
    warshall_floyd(dt);
    int k = in();
    REP(i, k) {
      int a = in() - 1, b = in() - 1, r = in();
      print(r ? dt[a][b] : dc[a][b]);
    }
  }

  return 0;
}

#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()

using namespace std;

typedef unsigned int uint;
typedef long long ll;

int main(){
  int n,m;
  while(scanf("%d%d",&n,&m), n+m){
    int time[100][100] = {{0}};
    int cost[100][100] = {{0}};
    REP(i,n){
      int a,b,c,d;
      scanf("%d%d%d%d",&a,&b,&c,&d);
      a--; b--;
      cost[a][b] = cost[b][a] = c;
      time[a][b] = time[b][a] = d;
    }
    int k;
    scanf("%d",&k);
    while(k --> 0){
      int p,q,type;
      int (*load)[100];
      scanf("%d%d%d",&p,&q,&type);
      if(type == 0) load = cost;
      else load = time;

      p--; q--;
      int memo[100];
      memset(memo, -1, sizeof(memo));
      priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > qq;
      qq.push(mp(0, p));
      while(qq.size()){
	int c = qq.top().f;
	int pos = qq.top().s;
	qq.pop();
	if(pos == q){
	  printf("%d\n",c);
	  break;
	}
	if(memo[pos] != -1)
	  continue;
	memo[pos] = c;
	REP(i,m){
	  if(memo[i] == -1 && load[pos][i] != 0)
	    qq.push(mp(c+load[pos][i], i));
	}
      }
    }
  }
  return 0;
}


#include <algorithm>
#include <array>
#include <assert.h>
#include <bitset>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstring>
#include <functional>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>

#include <map>
#include <math.h>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#include <stdint.h>

namespace asl
{
    template <typename T>
    using vec = std::vector<T>;

    template <typename T>
    std::istream &operator>>(std::istream &is, std::vector<T> &vec)
    {
        for (auto &value : vec)
            is >> value;
        return is;
    }

    template <typename T>
    struct fenwick
    {
        int n;
        std::vector<T> f;
        fenwick(int n) : n(n), f(n + 1) {}

        T query(int p)
        {
            T ret = 0;
            for (++p; p > 0; p -= p & -p)
                ret += f[p];
            return ret;
        }

        void update(int p, T x)
        {
            for (++p; p <= n; p += p & -p)
                f[p] += x;
        }

    };

    template <typename T>
    using BIT = fenwick<T>;
}

#include <experimental/optional>

#include <tuple>

namespace asl
{
    typedef long long i64;

}

#include <random>

#include <utility>

#define endl '\n'

using namespace std;
using namespace asl;

void solve()
{
    int n, q;
    cin >> n >> q;

    vec<int> val(n);
    cin >> val;

    BIT<i64> bit(n);

    for (int i = 0; i < n; ++i)
        bit.update(i, val[i]);

    while (q--)
    {
        int t;
        cin >> t;

        if (t == 0)
        {
            int p, x;
            cin >> p >> x;
            bit.update(p, x);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            cout << bit.query(r - 1) - bit.query(l - 1) << endl;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int t = 1;

    for (int i = 1; i <= t; ++i)
    {
        solve();
    }

    return 0;
}

#include<iostream>
#include<vector>
#include<string>

using namespace std;
vector<string> ans;
vector<char> alp;

int main(){

	for(int i = 0;i < 26;i++){
		char a = 'a' + i;
		alp.push_back(a);
	}
	for(int i = 0;i < 26;i++){
		char  A = 'A' + i;
		alp.push_back(A);
	}

	while(1){
		int n;
		cin >> n;
		if(n == 0) break;
		int k[100];
		for(int i = 0;i < n;i++) cin >> k[i];

		string s;
		cin >> s;

		for(int i = 0;i < s.size();i++){
			char cnum;
			if(s[i] >= 'a'){
				cnum = s[i] - 'a';
			}else cnum = s[i] - 'A' + 26;
			s[i] = alp[(cnum -k[i%n] +52)%52];
		}

		ans.push_back(s);
	}
	for(int i = 0;i < ans.size();i++)cout << ans[i] << endl;
	return 0;
}


#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, const char *argv[]) {
  vector<int> abc(3);
  int k;
  cin >> abc[0] >> abc[1] >> abc[2];
  cin >> k;

  vector<int>::iterator iter = max_element(abc.begin(), abc.end());
  size_t index = distance(abc.begin(), iter);

  abc[index] *= (int)pow(2.0, (double)k);
  cout << accumulate(abc.begin(), abc.end(), 0) << endl;

  return 0;
}

#include<bits/stdc++.h>
using namespace std ;
const int inf = 1012345678;

int main(){
  int64_t N  ;
  cin >> N ;

  int64_t a , b , c , d , e ;
  cin >> a >> b >> c >> d >> e ;
  int64_t min_t = min( a , min( min(b,c),min(d,e) ) ) ;
  //cout << min_t << endl ;

  if(N%min_t ==  0 ){
    cout << N/min_t + 4 << endl ;
  }
  else{
  	cout << (N/min_t) + 4 + 1 << endl ;
  }

  //975529666566238
}


#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	string s; cin>>s;
	int n=s.length();

	lint hist[128]={};
	rep(i,n) hist[s[i]]++;

	lint ans=1;
	for(int c='a';c<='z';c++) for(int d=c+1;d<='z';d++) {
		ans+=hist[c]*hist[d];
	}
	cout<<ans<<'\n';

	return 0;
}

#include<cstdio>
#include<iostream>
#include <memory>
#include<vector>
#include<algorithm>
using namespace std;

int calc(int a, int b, int ope) {
	if (ope == 0) return a + b;
	else return a - b;
}

int main(void) {
	string S;
	cin >> S;
	char ope[] = {'+', '-'};
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			for (int k = 0; k < 2; k++) {
				int ans = calc(S[0] - '0', S[1] - '0', i);
				ans = calc(ans, S[2] - '0', j);
				ans = calc(ans, S[3] - '0', k);
				if (ans == 7) {
					cout << S[0] << ope[i] << S[1] << ope[j] << S[2] << ope[k] << S[3] << "=7\n";
					return 0;
				}
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long LL;
const LL inf=0x3f3f3f3f3f3f3f3fll;
const int MX=200005;
int n,m,x,y;LL ad,f[MX],ans;
LL f1[MX],f2[MX];
void add1(int x,LL k){for(;x<=n&&k<f1[x];x+=x&-x)f1[x]=k;}
LL que1(int x){LL k=inf;for(;x;x-=x&-x)k=min(k,f1[x]);return k;}
void add2(int x,LL k){for(;x&&k<f2[x];x-=x&-x)f2[x]=k;}
LL que2(int x){LL k=inf;for(;x<=n;x+=x&-x)k=min(k,f2[x]);return k;}
void wk(){
	y=x,cin>>x;
	LL v=min(que1(x)+x,que2(x)-x)+ad;ad+=abs(x-y);
	if(v-ad<f[y])f[y]=v-ad,add1(y,f[y]-y),add2(y,f[y]+y);
}
int main(){
	int i;
	cin>>n>>m>>x>>y;
	for(i=1;i<=n;i++)f[i]=f1[i]=f2[i]=inf;
	for(f[y]=0,add1(y,-y),add2(y,y);m--;)wk();
	for(ans=inf,i=1;i<=n;i++)ans=min(ans,f[i]);
	cout<<ans+ad<<endl;
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define fr(i, l, r) for(int i = l;i < r;i++)

using namespace std;

const int N = 200001;
const ll OO = 1e13;
ll tr[3][4 * N];
ll lz[4 * N];

void init(int in, int l, int r){
  if(l == r){
    fr(i, 0, 3)
      tr[i][in] = 1e13 + 1ll * (i - 1) * l;
    return;
  }
  int m = (l + r) / 2;
  init(in * 2, l, m);
  init(in * 2 + 1, m + 1, r);
  fr(i, 0, 3)
    tr[i][in] = min(tr[i][2 * in], tr[i][2 * in + 1]);
}

void push(int in, int l, int r){
  fr(i, 0, 3)
    tr[i][in] += lz[in];
  if(l != r){
    lz[2 * in] += lz[in], lz[2 * in + 1] += lz[in];
  }
  lz[in] = 0;
}

void ass(int in, int l, int r, int j, ll v){
  push(in, l, r);
  if(l > j || r < j)
    return;
  if(l == r){
    fr(i, 0, 3)
      tr[i][in] = v + 1ll * l * (i - 1);
    return;
  }
  int m = (l + r) / 2;
  ass(in * 2, l, m, j, v);
  ass(in * 2 + 1, m + 1, r, j, v);
  fr(i, 0, 3)
    tr[i][in] = min(tr[i][2 * in], tr[i][2 * in + 1]);
}

struct MnRes{
  ll mn[3];
  MnRes(){
    mn[0] = mn[1] = mn[2] = OO;
  }
  MnRes(ll a, ll b, ll c){
    mn[0] = a, mn[1] = b, mn[2] = c;
  }
  void upd(const MnRes& ot){
    fr(i, 0, 3)
      mn[i] = min(mn[i], ot.mn[i]);
  }
};

MnRes get(int in, int l, int r, int s, int e){
  push(in ,l, r);
  if(l > e || r < s)
    return MnRes();

  if(l >= s && r <= e){
    return MnRes(tr[0][in], tr[1][in], tr[2][in]);
  }
  int m = (l + r) / 2;
  MnRes res = get(2 * in, l, m, s, e);
  res.upd(get(2 * in + 1, m + 1, r, s, e));
  return res;
}

void add(int in, int l, int r, int s, int e, ll v){
  push(in, l, r);
  if(l > e || r < s)
    return;
  if(l >= s && r <= e){
    lz[in] += v;
    push(in, l, r);
    return;
  }
  int m = (l + r) / 2;
  add(2 * in, l , m, s, e, v);
  add(2 * in + 1, m + 1, r, s, e, v);
  fr(i, 0, 3)
    tr[i][in] = min(tr[i][2 * in], tr[i][2 * in + 1]);
}
int n, q, a, b;
//
//void print(int in = 1, int l = 0, int r = n -1){
//  push(in, l, r);
//  printf("l= %d, r= %d, tr[0]= %lld, tr[1]= %lld, tr[2]= %lld, lz[0]= %lld, lz[1]= %lld, lz[2]= %lld\n", l, r, tr[0][in], tr[1][in], tr[2][in], lz[0][in], lz[1][in], lz[2][in]);
//  if(l == r){
//    return;
//  }
//  int m = (l + r) / 2;
//  print(2 * in, l, m);
//  print(2 * in + 1, m + 1, r);
//}

int x[N];

int main(){
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  cin >> n >> q >> a >> b;
  a--, b--;
  fr(i, 0, q){
    cin >> x[i];
    x[i]--;
  }
  init(1, 0, n - 1);
//  print();
  ass(1, 0, n - 1, a, abs(b - x[0]));
//  print();
  ass(1, 0, n - 1, b, abs(a - x[0]));
  for(int i = 1;i < q;i++){
    // calc dp[i][x[i]]
    MnRes r1 = get(1, 0, n - 1, 0, x[i]);
    MnRes r2 = get(1, 0, n - 1, x[i], n - 1);
    ll val = min(x[i] + r1.mn[0], r2.mn[2] - x[i]);
    add(1, 0, n - 1, 0, n - 1, abs(x[i] - x[i -1]));
    ass(1, 0, n - 1, x[i - 1], val);
//    print();
//    cout << endl;
  }
//  print();
  cout << get(1, 0, n - 1, 0, n - 1).mn[1] << endl;
//  cout << get(1, 0, n - 1, 0, n - 1).mn[1];
}


#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <string>
#include <cmath>
#include <cassert>
#define SIZE 100005

using namespace std;
typedef long long int ll;
typedef pair <ll,int> P;

ll B[SIZE],L[SIZE],U[SIZE];
P pos[SIZE];

int main()
{
	int n;
	ll X;
	scanf("%d %lld",&n,&X);
	ll sum=0;
	for(int i=0;i<n;i++)
	{
		scanf("%lld %lld %lld",&B[i],&L[i],&U[i]);
		pos[i]=P((X-B[i])*U[i]+B[i]*L[i],i);
		sum-=B[i]*L[i];
	}
	sort(pos,pos+n);
	ll ret=0;
	int last=0;
	for(int i=n-1;i>=0;i--)
	{
		P p=pos[i];
		if(sum+p.first>=0)
		{
			ret+=(ll) (n-i-1)*(ll) X;
			last=i+1;
			break;
		}
		sum+=p.first;
	}
  // cout<<ret<<" "<<last<<endl;
	ll mn=X;
	sum=-sum;
  // cout<<sum<<endl;
	for(int i=0;i<last;i++)
	{
		int v=pos[i].second;
		mn=min(mn,(sum+L[v]-1)/L[v]);
		ll nsum=sum+B[v]*(U[v]-L[v]);
		mn=min(mn,(nsum+U[v]-1)/U[v]);
	}
	for(int i=last;i<n;i++)
	{
		int v=pos[i].second;
		ll nsum=sum+pos[i].first-pos[last-1].first;
		mn=min(mn,(nsum+L[v]-1)/L[v]);
		ll nsum2=nsum+B[v]*(U[v]-L[v]);
		mn=min(mn,(nsum2+U[v]-1)/U[v]);
	}
	printf("%lld\n",ret+mn);
	return 0;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

int read(){
    int x=0;bool f=0;char c=getchar();
    while(c<'0'||c>'9') f|=c=='-',c=getchar();
    while(c>='0'&&c<='9') x=x*10+(c^48),c=getchar();
    return f?-x:x;
}

#define MAXN 100000
#define LL long long

int N,X;
LL Sum[MAXN+5],Org,D[MAXN+5];
struct Range{
    LL tot;
    int l,r,id;
}A[MAXN+5];
bool cmp(Range i,Range j){
    return i.tot>j.tot;
}

bool Check(LL expt){
    LL Max=0;
    LL All=expt/X,Rest=expt%X;
    for(int i=1;i<=N;i++){
        LL l=min(Rest,D[A[i].id]);
        LL tmp=i>All?Sum[All]:(Sum[All+1]-A[i].tot);
        Max=max(Max,tmp+l*A[i].l+(Rest-l)*A[i].r);
    }
    return Max>=Org;
}

int main(){
    N=read(),X=read();
    for(int i=1;i<=N;i++){
        D[i]=read();
        A[i].id=i;
        A[i].l=read(),A[i].r=read();
        A[i].tot=D[i]*A[i].l+(X-D[i])*A[i].r;
        Org+=D[i]*A[i].l;
    }
    sort(A+1,A+N+1,cmp);
    for(int i=1;i<=N;i++)
        Sum[i]=Sum[i-1]+A[i].tot;
    LL Left=-1,Right=(LL)X*N;
    while(Left+1<Right){
        LL mid=(Left+Right)>>1;
        if(Check(mid))
            Right=mid;
        else
            Left=mid;
    }
    printf("%lld",Right);
}


#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int n,num[3]={0};
    cin>>n;
    cin>>num[0]>>num[1];
    if(n==3)cin>>num[2];
    sort(num,num+2);
    for(int i=1;i<=num[0];i++){
        if(num[0]%i==0&&num[1]%i==0&&num[2]==0)cout<<i<<endl;
        else if(num[0]%i==0&&num[1]%i==0&&num[2]%i==0)cout<<i<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b,a%b);
}

int main(){
    ll n; cin>>n;
    if(n==2){
        ll a,b; cin>>a>>b;
        ll x=gcd(a,b);
        rep(i,x+1){
            if(i==0)continue;
            if(x%i==0) cout<<i<<endl;
        }
    }else{
        ll a,b,c; cin>>a>>b>>c;
        ll x=gcd(a,b);
        ll y=gcd(c,x);
        rep(i,y+1){
            if(i==0)continue;
            if(y%i==0) cout<<i<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <string>
using namespace std;

int main(void) {

  string str;

  while(getline(cin, str)) {
    while(1) {
      for(int i=0; i<str.length(); i++) {
          if(str[i] != ' ' && str[i] != '.') {
              if(str[i] != 'z'){
                        str[i] += 1;
                    }else{
                        str[i] = 'a';
                    }
          }
      }

          if(str.find("the")!=string::npos||str.find("this")!=string::npos||str.find("that")!=string::npos) {
          cout << str << endl;
          break;

    }
    }
  }
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;

int main() {
    string s;
    while(getline(cin,s)) {
        string t;
        rep(j,0,26) {
            t.clear();
            rep(i,0,s.length()) {
                if('a' <= s[i] && s[i] <= 'z') {
                    int val = (s[i] - 'a' + j) % 26;
                    t += ('a' + val);
                }
                else t += s[i];
            }
            if(t.find("this") != string::npos) break;
            else if(t.find("the") != string::npos) break;
            else if(t.find("that") != string::npos) break;
        }
        cout << t << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll h,w,a,b;
    cin >> h >> w >> a >> b;
    if(h == 1){
        for(i = 0;i < a;++i) cout << 0;
        for(i = a;i < w;++i) cout << 1;
        cout << endl;
        return 0;
    }else if(w == 1){
        for(i = 0;i < b;++i){
            cout << 0 << endl;
        }
        for(i = b;i < h;++i){
            cout << 1 << endl;
        }
        return 0;
    }
    for(i = 0;i < h;++i){
        for(j = 0;j < w;++j){
            if(i < b && j < a) cout << 0;
            else if(i >= b && j >= a) cout << 0;
            else cout << 1;
        }
        cout << endl;
    }

    return 0;
}

#include <bits/stdc++.h>

using namespace std;

template< typename T >
struct edge {
  int src, to;
  T cost;

  edge(int to, T cost) : src(-1), to(to), cost(cost) {}

  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

  edge &operator=(const int &x) {
    to = x;
    return *this;
  }

  operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
void warshall_floyd(Matrix< T > &g, T INF) {
  for(int k = 0; k < g.size(); k++) {
    for(int i = 0; i < g.size(); i++) {
      for(int j = 0; j < g.size(); j++) {
        if(g[i][k] == INF || g[k][j] == INF) continue;
        g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
      }
    }
  }
}

int main() {
  int V, E;
  scanf("%d %d", &V, &E);
  Matrix< int > mat(V, vector< int >(V, INT_MAX));
  for(int i = 0; i < V; i++) mat[i][i] = 0;
  for(int i = 0; i < E; i++) {
    int x, y, z;
    scanf("%d %d %d", &x, &y, &z);
    mat[x][y] = z;
  }
  warshall_floyd(mat, INT_MAX);
  for(int i = 0; i < V; i++) {
    if(mat[i][i] < 0) {
      puts("NEGATIVE CYCLE");
      return 0;
    }
  }
  for(int i = 0; i < V; i++) {
    for(int j = 0; j < V; j++) {
      if(j > 0) putchar(' ');
      if(mat[i][j] == INT_MAX) printf("INF");
      else printf("%d", mat[i][j]);
    }
    putchar('\n');
  }
}


#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

struct edge {
	ll to;
	ll cost;
};

//トポソ
void toposo_(vector<vector<edge>>& g, vector<int>& used, vector<int>& l, int pos) {
	if (!used[pos]) {
		used[pos] = 1;
		for (int i = 0; i < g[pos].size(); i++) {
			toposo_(g, used, l, g[pos][i].to);
		}
		l.push_back(pos);
	}
}
vector<int> toposo(vector<vector<edge>>& g) {
	vector<int> u(g.size(), 0), ret;
	for (int i = 0; i < g.size(); i++)toposo_(g, u, ret, i);
	reverse(ret.begin(), ret.end());
	return ret;
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<vector<edge>> g(N);
	vector<vector<int>> pars(N);
	for (int i = 0; i < N + M - 1; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back({ v,1 });
		pars[v].push_back(u);
	}

	vector<int> a = toposo(g);
	vector<int> used(N, 0), ans(N);
	for (int i = 0; i < N; i++) {
		if (i == 0) {
			ans[a[i]] = -1;
			used[a[i]] = i+1;
		}
		else {
			ll t1, t2 = -1;
			for (int j = 0; j < pars[a[i]].size(); j++) {
				if (used[pars[a[i]][j]] != 0) {
					if (t2 < used[pars[a[i]][j]]) {
						t1 = pars[a[i]][j];
						t2 = used[pars[a[i]][j]];
					}
				}
			}
			ans[a[i]] = t1;
			used[a[i]] = i + 1;
		}
		//cout << a[i] << endl;
	}
	for (int i = 0; i < N; i++) {
		cout << ans[i] + 1 << endl;
	}
}

#include <fstream>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sstream>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <random>

using namespace std;

#define INT_MAX_VALUE 2147483647
#define LONG_LONG_MAX_VALUE 9223372036854775807
#define ll long long
#define ld long double

struct XX{
    int s;
    int t;
};

class xxGreater {
public:
    bool operator()(const XX& riLeft, const XX& riRight) const {
        //第2条件
        if((riLeft.t) == (riRight.t)){
            return riLeft.s < riRight.s;//<:昇順(小さいものから順番)、>:降順(大きいものから順番)
            //プライオリティキューの場合は > で、top()すると値の小さいものがとれる
        }
        //第1条件
        return (riLeft.t) < (riRight.t);
    }
};

//map<long long,long long> prime_f(long long n){
//    map<long long,long long>res;
//    for(int i=2;i*i<=n;i++){
//        while(n%i==0){
//            ++res[i];
//            n/=i;
//        }
//    }
//    if(n!=1)res[n]=1;
//    return res;
//}

int ppar[200002]; //親
int rrank[200002];//木の深さ
void _init(int n){
    for(int i=1;i<=n;i++){
        ppar[i]=i;
        rrank[i]=0;
    }
}

int find(int x){
    if(ppar[x]==x){
        return x;
    }else{
        return ppar[x]=find(ppar[x]);
    }
}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(x==y){
        return;
    }
    if(rrank[x]<rrank[y]){
        ppar[x]=y;
    }else{
        ppar[y]=x;
        if(rrank[x]==rrank[y]){
            rrank[x]++;
        }
    }
}
bool same(int x,int y){
    return find(x)==find(y);
}

int ppar2[200002]; //親
int rrank2[200002];//木の深さ
void _init2(int n){
    for(int i=1;i<=n;i++){
        ppar2[i]=i;
        rrank2[i]=0;
    }
}

int find2(int x){
    if(ppar2[x]==x){
        return x;
    }else{
        return ppar2[x]=find2(ppar2[x]);
    }
}

void unite2(int x,int y){
    x=find2(x);
    y=find2(y);
    if(x==y){
        return;
    }
    if(rrank2[x]<rrank2[y]){
        ppar2[x]=y;
    }else{
        ppar2[y]=x;
        if(rrank2[x]==rrank2[y]){
            rrank2[x]++;
        }
    }
}
bool same2(int x,int y){
    return find2(x)==find2(y);
}

int main(int argc, const char * argv[])
{
    //scanf("%s",S);
    //scanf("%d",&N);
    //scanf("%lld %lld",&target1,&target2);
    //sscanf(tmp.c_str(),"%dd%d%d",&time[i], &dice[i], &z[i]);
    //getline(cin, target);
    //ifstream ifs("a.txt");//テスト用
    //ifs >> a;
    //ここから

    //入力高速化
    ios::sync_with_stdio(false);
    cin.tie(0);

    int N,K,L;
    cin >> N >> K >> L;

    int tmp[100000],tmp2[100000];
    int ttmp[100000],ttmp2[100000];
    for(int i=0;i<K;i++){
        cin >> tmp[i]>>tmp2[i];
    }
    for(int i=0;i<L;i++){
        cin >> ttmp[i]>>ttmp2[i];
    }
    _init(N);
    _init2(N);

    for(int i=0;i<L;i++){
        unite2(ttmp[i],ttmp2[i]);
    }
    for(int i=0;i<K;i++){
        unite(tmp[i],tmp2[i]);
        //ここでつなげる、つなげない判断はしてはいけない
        // a+b c+d (道路)
        // a+b-c (鉄道)
        // 鉄道でb-cを結んでおかないと、b-dが来た時にcとつながれない
    }

    int a2[200002];
    map<pair<int,int>,int>a;
    for(int i=1;i<=N;i++){
        a[make_pair(find(i),find2(i))]++;
    }
    for(int i=1;i<=N;i++){
        a2[i]=a[make_pair(find(i),find2(i))];
    }
    for(int i=1;i<=N;i++){
        cout << a2[i];
        if(i!=N){
            cout << " ";
        }else{
            cout << endl;
        }
    }

    //ここまで
    //cout << "ans" << endl;
    //printf("%.0f\n",ans);//小数点以下表示なし
    //printf("%.7f\n",p);

    return 0;
}


#include<iostream>

using namespace std;

class DICE {
	enum {
		Top,
		Front,
		Right,
		Left,
		Rear,
		Bottom
	};

	void Roll(const char*Directions) {
		for (int i = 0; Directions[i] != '\0'; i++) {
			Roll(Directions[i]);
		}
	}

	void Roll(const char Direction) {
		int tmpTop = Num[Top];

		switch (Direction) {
		case'E':
			Num[Top] = Num[Left];
			Num[Left] = Num[Bottom];
			Num[Bottom] = Num[Right];
			Num[Right] = Num[tmpTop];
			break;
		case'N':
			Num[Top] = Num[Front];
			Num[Front] = Num[Bottom];
			Num[Bottom] = Num[Rear];
			Num[Rear] = tmpTop;
			break;
		case'S':
			Num[Top] = Num[Rear];
			Num[Rear] = Num[Bottom];
			Num[Bottom] = Num[Front];
			Num[Front] = tmpTop;
			break;
		case'W':
			Num[Top] = Num[Right];
			Num[Right] = Num[Bottom];
			Num[Bottom] = Num[Left];
			Num[Left] = tmpTop;
			break;
		}
	}

	bool SameDiceDirectionFlag(DICE Dice) {
		for (int i = 0; i < 6; i++) {
			if (Num[i] != Dice.Num[i])return false;
		}
		return true;
	}

public:
	int Num[6];

	bool SameDiceNoneDirectionFlag(DICE Dice) {
		const char Directions[][3] = { "N","N","N","NW","WW","\0" };

		for (int i = 0; i < 6; i++) {
			if (Num[Top] == Dice.Num[Top]) {
				for (int j = 0; j < 4; j++) {
					if (SameDiceDirectionFlag(Dice))return true;

					int tmpFront = Dice.Num[Front];
					Dice.Num[Front] = Dice.Num[Right];
					Dice.Num[Right] = Dice.Num[Rear];
					Dice.Num[Rear] = Dice.Num[Left];
					Dice.Num[Left] = tmpFront;
				}
			}

			Dice.Roll(Directions[i]);
		}

		return false;
	}

};

int main() {
	DICE Dice[101];
	int n;

	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 6; j++)cin >> Dice[i].Num[j];
	}

	for (int i = 1; i < n; i++) {
		if (Dice[0].SameDiceNoneDirectionFlag(Dice[i])) {
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;

	return 0;
}


#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
//#define mod 998244353
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int dp1[310][90909] = { 0 };
int dp2[310][90909] = { 0 };

signed main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N, sum = 0;
	int mod = 998244353;
	cin >> N;
	VI A(N);
	REP(i, N) {
		cin >> A[i];
		sum += A[i];
	}

	dp1[0][0] = 1;
	REP(i, N) {
		REP(j, 90909) {
			if (j + A[i] < 90909) {
				dp1[i + 1][j + A[i]] += dp1[i][j];
				dp1[i + 1][j + A[i]] %= mod;
			}
			dp1[i + 1][j] += 2 * dp1[i][j];
			dp1[i + 1][j] %= mod;
		}
	}

	int x = 0;
	REP(j, 90909) {
		if (j * 2 >= sum) {
			x += dp1[N][j];
			x %= mod;
		}
	}

	dp2[0][0] = 1;
	REP(i, N) {
		REP(j, 90909) {
			if (j + A[i] < 90909) {
				dp2[i + 1][j + A[i]] += dp2[i][j];
				dp2[i + 1][j + A[i]] %= mod;
			}
			dp2[i + 1][j] += dp2[i][j];
			dp2[i + 1][j] %=mod;
		}
	}

	int y = (sum % 2 == 0) ? dp2[N][sum / 2] : 0;

	int ans = 1;
	REP(i, N) {
		ans *= 3;
		ans %= mod;
	}
	//cout << x << endl;
	//cout << y << endl;
	//cout << ans << endl;
	//cout << (ans-3*x+3*y)%mod << endl;
	ans = (ans - 3 * x + 8 * mod) % mod;
	ans += 3 * y;

	cout << ans % mod << endl;

	return 0;
}

// I SELL YOU...!
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#define MOD 1000000007
#define MAX_H 110
#define MAX_W 10
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
ll h,w,k,fr;
ll dp[MAX_H][MAX_W]={};
ll pat_dp[MAX_W][2];
ll pat[MAX_W];
signed main(){
  ll st,le,ri;
  init_io();
  cin >> h >> w >> k;
  if(w==1){
    cout << 1<<endl;
    return 0;
  }
  dp[0][0] = 1;
  pat_dp[0][0] = 0;
  pat_dp[0][1] = 0;
  pat[0] = 1;

  pat_dp[1][0] = 1;
  pat_dp[1][1] = 0;
  pat[1] = 1;

  for(int i=2;i<MAX_W;i++){
    pat_dp[i][0] = pat_dp[i-1][0]+pat_dp[i-1][1];
    pat_dp[i][1] = pat_dp[i-1][0];

    pat_dp[i][0] %= MOD;
    pat_dp[i][1] %= MOD;

    pat[i] = (pat_dp[i][0]+pat_dp[i][1])%MOD;
  }
  for(int i=1;i<=h;i++){
    for(int j=0;j<w;j++){
      st = dp[i-1][j];
      st *= (pat[j]*pat[w-1-j])%MOD;
      st %= MOD;

      le = 0;
      ri = 0;

      if(j!=0){
        le = (dp[i-1][j-1]*(pat[j-1]*pat[w-1-j])%MOD)%MOD;
      }
      if(j!=w-1){
        ri = (dp[i-1][j+1]*(pat[j]*pat[w-2-j]))%MOD;
      }
      dp[i][j] = (st+ri+le)%MOD;
    }
  }
  cout << dp[h][k-1]<<endl;
}


#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fr(i,a,b) for(int i = a ; i <= b ; ++i)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define pb push_back
#define fst first
#define snd second
using namespace __gnu_pbds;
using ordered_set =
 tree<int, null_type,less<int>,
 rb_tree_tag,tree_order_statistics_node_update>;
//find_by_order(k):returns iterator to kth element starting from 0
//order_of_key(k):returns count of elements strictly smaller than k
typedef long long ll;typedef pair<int, int> pii;
typedef vector<int> vi;typedef long double ld;
template<class T>
using min_heap = priority_queue<T,vector<T>,greater<T>>;
template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template<typename T> T lcm(T a, T b){return(a*(b/gcd(a,b)));}
template<class T> void re(T& x) { cin >> x; }
template<typename T>
void remdup(vector<T>& v) {
	sort(all(v)); v.erase(unique(all(v)), v.end());
}
template<typename T> void re(vector<T> &v) {trav(i,v) cin >> i;}
template<class H, class... T> void re(H& h, T&... t) { re(h); re(t...); }
void unsyncIO() { ios_base::sync_with_stdio(0); cin.tie(0); }
#ifdef np
#include "/home/o_o/MyCodes/pr.h"
#else
#define trace(...)
#endif

#define MOD 1000000007

void solve(){
	int cnt = 1 ;
	int n , x , t ;
	re(n,x,t);
	while(cnt*x<n) cnt++;
	cout << cnt * t << endl;
}

signed main() {
	unsyncIO();
	int tt =1 ;
	// cin >> tt;
	rep(i,0,tt) solve();

#ifdef np
	cout <<endl<<endl<< "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    cin >> N;

    if (N == 1) {
        cout << "Hello"
             << " "
             << "World" << endl;
    } else if (N == 2) {
        int A, B;
        cin >> A >> B;

        cout << A + B << endl;
    }
}


#include<cstdio>

int main()
{
while(true) {

int a, b, c, n;
int test[3000], r[1000];
int ans[1000];
scanf("%d%d%d", &a, &b, &c);
if(a == 0)
break;
scanf("%d", &n);
for(int i = 0; i < n; ++i) {
scanf("%d%d%d%d", test + i * 3, test + i * 3 + 1, test + i * 3 + 2, r + i);
test[i * 3] -= 1, test[i * 3 + 1] -= 1, test[i * 3 + 2] -= 1;
}

for(int i = 0; i < a + b + c; ++i)
ans[i] = 2;
for(int i = 0; i < n; ++i) {
if(r[i] != 1)
continue;
for(int j = i * 3; j < i * 3 + 3; ++j)
ans[test[j]] = 1;
}
for(int i = 0; i < n; ++i) {
if(r[i] != 0)
continue;
int correct = 0;
for(int j = i * 3; j < i * 3 + 3; ++j)
correct += (ans[test[j]] == 1);
if(correct != 2)
continue;
for(int j = i * 3; j < i * 3 + 3; ++j) {
if(ans[test[j]] != 1)
ans[test[j]] = 0;
}
}
for(int i = 0; i < a + b + c; ++i)
printf("%d\n", ans[i]);
}
return 0;
}

#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <math.h>
#include <algorithm>

const int coin[6] = { 500,100,50,10,5,1 };

using namespace std;

struct Expm { int a, b, c, r; };

int main(){

	/*int answer[5][2] = { 0 };
	int n = 0;

	int buf[100];
	int ndataset;
	for (ndataset = 0; ; ndataset++) {

		cin >> n;
		if (n == 0) break;

		for (int i = 0; i < n; i++) {
			cin >> buf[i];
		}

		sort(&buf[0], &buf[n]);

		int scoreT = 0;
		int scoreH = 0;
		for (int i = 0; i < n; i++) {
			int sbase = 2 * i + 1 - buf[i];
			if (sbase > 0) {
				scoreH = max(abs(sbase), scoreH);
			}
			else {
				scoreT = max(abs(sbase), scoreT);
			}
		}
		if (scoreH > scoreT) scoreT = 0;
		if (scoreH <= scoreT) scoreH = 0;
		answer[ndataset][0] = scoreT;
		answer[ndataset][1] = scoreH;

	} // dataset

	for (int i = 0; i < ndataset; i++) {
		cout << answer[i][0] << endl;
		cout << answer[i][1] << endl;
	}*/

	int resA[5][100]; int resB[5][100]; int resC[5][100];
	int numa[5], numb[5], numc[5], nume[5];
	int set = 0;

	for (;; set++) {

		Expm expm[1000];

		cin >> numa[set] >> numb[set] >> numc[set];
		if (numa[set] == 0 && numb[set] == 0 && numc[set] == 0) break;

		for (int i = 0; i < numa[set]; i++) resA[set][i] = 2;
		for (int i = 0; i < numb[set]; i++) resB[set][i] = 2;
		for (int i = 0; i < numc[set]; i++) resC[set][i] = 2;

		cin >> nume[set];
		for (int i = 0; i < nume[set]; i++) {
			cin >> expm[i].a
				>> expm[i].b
				>> expm[i].c
				>> expm[i].r;
			if (expm[i].r) {
				resA[set][expm[i].a-1] = resB[set][expm[i].b-numa[set]-1] =
					resC[set][expm[i].c - numa[set] - numb[set] -1] = 1;
			}
		}
		for (int i = 0; i < nume[set]; i++) {
			if (expm[i].r) continue;
			if (resA[set][expm[i].a-1] == 1 &&
				resB[set][expm[i].b - numa[set] -1] == 1)
				resC[set][expm[i].c - numa[set] - numb[set] -1] = 0;
			if (resC[set][expm[i].c - numa[set] - numb[set] -1] == 1 &&
				resB[set][expm[i].b - numa[set] -1] == 1)
				resA[set][expm[i].a-1] = 0;
			if (resA[set][expm[i].a-1] == 1 &&
				resC[set][expm[i].c - numa[set] - numb[set] -1] == 1)
				resB[set][expm[i].b - numa[set] -1] = 0;
		}
	}

	for (int j = 0; j < set; j++) {
		for (int i = 0; i < numa[j]; i++)
			cout << resA[j][i] << endl;
		for (int i = 0; i < numb[j]; i++)
			cout << resB[j][i] << endl;
		for (int i = 0; i < numc[j]; i++)
			cout << resC[j][i] << endl;
	}

	return 0;
}


#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;

int d12, d13, d23, T;

void comparar () {
    int t1=d12+d23;
    int t2=d13+d23;
    int t3=d12+d13;
    if (t1>=t2) {
        T=min(t3,t2);
    } else {
        T=min(t1,t3);
    }
}

int main () {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin>>d12>>d13>>d23;
    comparar();
    cout<<T;

   return 0;
}

#include <atcoder/fenwicktree>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

ll solve() {
    ll N, Q, t, a;
    cin >> N >> Q;
    atcoder::fenwick_tree<ll> ft(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        ft.add(i, a);
    }
    vector<ll> ans;
    for ( int q = 0; q < Q; q++ ) {
        cin >> t;
        if ( t == 0 ) {
            ll p, x;
            cin >> p >> x;
            ft.add(p,x);
        } else {
            ll l, r;
            cin >> l >> r;
            ans.push_back(ft.sum(l,r));
        }
    }
    for ( auto a : ans ) {
        cout << a << "\n";
    }
    return 0;
}

int main() {
    solve();
    return 0;
}


#define _USE_MATH_DEFINES	//M_PI
#include <iostream>			//std::cout, std::cin
#include <string>			//std::string
#include <vector>			//std::vector
#include <valarray>			//std::valarray	??°????????????????¬???????
#include <algorithm>		//std::sort
#include <time.h>			//localtime_s
#include <cstdlib>			//abs
#include <cmath>			//abs, pow, sqrt, sin, cos,
#include <fstream>			//std::ifstream
#include <iomanip>			//std::setprecision

int main(void) {

	//test??¨
	//std::ifstream in("test.txt");
	//std::cin.rdbuf(in.rdbuf());

	int dice[6] = {};
	for (int i = 0; i < 6; i++) {
		std::cin >> dice[i];
	}

	int temp[6] = {};

	std::string order;
	std::cin >> order;
	for (int i = 0; i < order.length(); i++) {
		switch (order[i]) {
		case 'E':
			temp[0] = dice[3];
			temp[1] = dice[1];
			temp[2] = dice[0];
			temp[3] = dice[5];
			temp[4] = dice[4];
			temp[5] = dice[2];
			for (int j = 0; j < 6; j++) {
				dice[j] = temp[j];
			}
			break;
		case 'N':
			temp[0] = dice[1];
			temp[1] = dice[5];
			temp[2] = dice[2];
			temp[3] = dice[3];
			temp[4] = dice[0];
			temp[5] = dice[4];
			for (int j = 0; j < 6; j++) {
				dice[j] = temp[j];
			}
			break;
		case 'S':
			temp[0] = dice[4];
			temp[1] = dice[0];
			temp[2] = dice[2];
			temp[3] = dice[3];
			temp[4] = dice[5];
			temp[5] = dice[1];
			for (int j = 0; j < 6; j++) {
				dice[j] = temp[j];
			}
			break;
		case 'W':
			temp[0] = dice[2];
			temp[1] = dice[1];
			temp[2] = dice[5];
			temp[3] = dice[0];
			temp[4] = dice[4];
			temp[5] = dice[3];
			for (int j = 0; j < 6; j++) {
				dice[j] = temp[j];
			}
			break;
		default:;
		}
	}
	std::cout << dice[0] << std::endl;

}

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>

using namespace std;

int partition(int *A,int p,int r)
{
	int x,j,temp;

	x = A[r];
	j = p-1;

	for(int i = p; i < r; i++)
	{
		if (A[i] <= x)
		{
			j++;
			temp = A[j];
			A[j] = A[i];
			A[i] = temp;
		}
	}

	temp = A[j+1];
	A[j+1] = A[r];
	A[r] = temp;

	return j+1;
}

int main()
{
	int n,a[100000] = {0};
	int q;

	scanf("%d", &n);

	for(int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}

	q = partition(a,0,n-1);

	for(int i = 0; i < n; i++)
	{
		if (i == q)
		{
			printf("[%d] ", a[i]);
		}else if (i == n-1)
		{
			printf("%d\n", a[i]);
		}else
		{
			printf("%d ", a[i]);
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;

    int cnt = 0;
    for (int n = a; n <= b; n++) {
        if (n / 10000 == n % 10 && (n / 1000) % 10 == (n / 10) % 10) {
            cnt ++;
        }
    }
    put(cnt);
    return 0;
}

/*Be patient && calm!
All our dreams can come true, if we have the courage to pursue them.
I fear not the man who has practiced 10,000 kicks once, but I fear the man who has practiced one kick 10,000 times.
Do not pray for an easy life, pray for the strength to endure a difficult one.
When something is important enough, you do it even if the odds are not in your favor.
First, solve the problem. Then, write the code.
Fix the cause, not the symptom.
Simplicity is the soul of efficiency.
Make it work, make it right, make it fast.
No matter how hard it gets, NEVER GIVE UP*/

#include <bits/stdc++.h>

#define pb push_back
#define MP make_pair
#define ALL(r) (r).begin(),(r).end()

typedef long long int ll;

#define FOR(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; ++i )
#define FORN(i,m,n) for(ll i=(ll)(m-1) ; i >= (ll) (n) ; --i )

#define RUN_FAST ios::sync_with_stdio(false);

using namespace std;

void solve()
{
    ll a,b,c,d,m,n,p,q,r,x,y,z,aa,bb,cc,dd,h; //variable
    ll i,j,k,l; //pointer
    ll cnt=0,cnt1=0,cnt2=0,cnt3=0,sum=0,mx=LLONG_MIN,mn=LLONG_MAX; //counter
    ll flag=0,flag2=0; //flag
    vector <ll> vec1,vec2,vec3;
    string s1,s2,s3;

    //PULOK SAHA
    //BMO

    cin >> a >> b;

    FOR(i,a,b+1)
    {
        s1=to_string(i);
        l = 0;
        h=s1.size()-1;
        flag=0;
        while (h > l)
        {
            if (s1[l++] != s1[h--])
            {
                flag=1;
                break;
            }
        }
        if(!flag)
            cnt++;
    }
    cout << cnt << endl;

}

int main()
{
    RUN_FAST
    //PULOK SAHA
    //BMO

    ll t=1;//test case

    //cin >> t;
    while(t--)
    {
        solve();
    }

    return 0;
}

//PULOK SAHA


#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
#include <fstream>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<string> a;

bool cmp(string s, string t) {
    if (s.length() != t.length()) return s.length() < t.length();
    return s < t;
}

void sol(string s) {
    a.push_back(s);
    if (s.length() == 10) return;
    if (s.back() != '0') {
        s += (s.back() - 1);
        sol(s);
        s.pop_back();
    }
    s += (s.back());
    sol(s);
    s.pop_back();
    if (s.back() != '9') {
        s += (s.back() + 1);
        sol(s);
        s.pop_back();
    }
}

int main() {
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << ' ' << a << ' ' << b;
}

#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int A, B, C;
  cin>>A>>B>>C;
  cout<<C<<" "<<A<<" "<<B<<endl;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if (A + B == C + D)
  {
    cout <<"Balanced" << endl;
  }
  else if (A + B <= C + D)
  {
    cout << "Right" << endl;
  }
  else if (A + B >= C + D)
  {
    cout << "Left" << endl;
  }
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int k;cin>>k;
	string s;cin>>s;
	int n=s.length();
	if(n<=k) cout<<s<<"\n";
	else
	{
		string s1="";
		for(int i=0;i<k;i++)
		s1=s1+s[i];
		s1=s1+"...";
		cout<<s1<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std ;

int main(){
  int64_t N ;
  cin >> N ;
  int P = N/26 ;
  vector<char> namae(100)   ;
  int i = 0 ;
    //cout << N << " " << i << endl ;

  while(N != 0 ){
    N-- ;
    int M = N % 26 ;
  	namae.at(i)  =  'a' + M ;
    N  /= 26 ;
    i++ ;

    //cout << N << " " << i << endl ;
  }

  for(int j = i - 1; j >= 0 ; j--){
    cout << namae.at(j) ;
  }

}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<
    pair<int, int>,
    null_type,
    less_equal<pair<int, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << (z) << ' '
#define cnl(z) cout << (z) << '\n'
#define M1 1000000007
#define M2 998244353
#define MAXN 300005
#define INF (1ll << 60)
#define endl "\n"
#define garr(ip)       \
    for (auto &x : ip) \
        cin >> x;
#define parr(ip)          \
    for (auto &x : ip)    \
        cout << x << " "; \
    cout << endl;
#define nl cout << endl
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vp;

void solve(int testCaseNumber = 1)
{
    int n;
    cin >> n;
    string ans;
    while (n > 0)
    {
        n--;
        ans += 'a' + n % 26;
        n /= 26;
    }
    reverse(all(ans));
    cnl(ans);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}


# include <iostream>
using namespace std;

int gcd(int a, int b){
  return (b==0) ? a : gcd(b, a%b);
}

int main(){

  int n, k;
  cin >> n >> k;

  int g = 0, m = 0;
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    g = gcd(x, g);
    m = max(x, m);
  }

  if(k <= m && k % g == 0) cout << "POSSIBLE";
  else cout << "IMPOSSIBLE";
  cout << endl;
  return 0;
}

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
ll gcd(ll x,ll y){
    if (y == 0) return x;
    return gcd(y, x%y);
}
int main(void){
    ll n,k;cin>>n>>k;
    vector<ll> a(n);
    rep(i,n) cin>>a[i];
    ll g=a[0];
    rep(i,n) g=gcd(g,a[i]);
    sort(a.rbegin(),a.rend());
    rep(i,n){
        if(a[i]<k)break;
        if((a[i]-k)%g==0){
            cout<<"POSSIBLE"<<endl;
            return 0;
        }
    }
    cout<<"IMPOSSIBLE"<<endl;
}


//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>

#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
#define INF 1000000000 //2000000000
#define LINF 1000000000000000000 //9000000000000000000
#define PI 3.14159265358979
#define MAXI 7500000

using namespace std;
typedef long long int ll;
typedef pair< long long int, long long  int> P;

int dy[5] = { 0,0,1,-1,0 };
int dx[5] = { 1,-1,0,0,0 };

int main(void) {

	while (1) {
		int n;

		cin >> n;
		if (n == 0) {
			break;
		}

		vector<string> l(n);
		vector<int> p(n), a(n), b(n), c(n), d(n), e(n), f(n), s(n), m(n), time(n), money(n);
		vector<double>adv(n);
		vector< pair<double, string> > pa(n);

		FOR(i, 0, n - 1) {
			cin >> l[i] >> p[i] >> a[i] >> b[i] >> c[i] >> d[i] >> e[i] >> f[i] >> s[i] >> m[i];
			int timetmp = 0;
			int moneytmp = 0;
			timetmp = a[i] + b[i] + c[i] + (d[i] + e[i])*m[i];
			moneytmp = f[i] * m[i] * s[i];
			moneytmp -= p[i];
			adv[i] = (double)moneytmp / (double)timetmp;
			pa[i].first = adv[i];
			pa[i].second = l[i];

			//cout << moneytmp << " " << timetmp << endl;
		}

		sort(pa.begin(), pa.end());

		double tmp;
		int first;
		int second;

		RFOR(i, n - 1, 0) {
			tmp = pa[i].first;
			first = i;
			second = i;
			RFOR(j, i-1, 0) {
				//cout << i << " " << j << " " << tmp << " " << pa[j].first << endl;
				if (tmp == pa[j].first) {
					if (j == 0) {
						second = 0;
						break;
					}
					continue;
				}
				else {
					second = j + 1;
					break;
				}
			}
			i = second;
			//cout << first << " " << second << endl;
			FOR(j, second, first) {
				cout << pa[j].second << endl;
			}

		}

		/*RFOR(i, n - 1, 0) {
			cout << pa[i].second << endl;
		}*/

		cout << "#" << endl;

	}

	return 0;
}


#pragma GCC optimize(2)
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define mp make_pair
#define pb push_back

#define eprintf(...) fprintf(stderr, __VA_ARGS__)

const ll linf = 1e18 + 7;

struct segment_tree {
	static const int maxn = 1 << 18;
	pair <ll, int> mn[maxn << 1];
	void init() {
		for (int i = 1; i < (maxn << 1); ++ i)
			mn[i] = mp(linf, -1);
	}
	void upd(int x, ll v) {
		mn[x + maxn] = mp(v, x);
		for (x += maxn; x >>= 1; )
			mn[x] = min(mn[x << 1], mn[x << 1 | 1]);
	}
	pair <ll, int> qry(int l, int r) {
		pair <ll, int> ans = mp(linf, -1);
		for (l += maxn, r += maxn; l < r; l >>= 1, r >>= 1) {
			if (l & 1) ans = min(ans, mn[l ++]);
			if (r & 1) ans = min(ans, mn[-- r]);
		}
		return ans;
	}
} seg0, seg1;

struct union_find {
	static const int maxn = 2e5 + 5;
	int fa[maxn];
	vector <int> v[maxn];
	void init() {
		for (int i = 0; i < maxn; ++ i)
			fa[i] = i, v[i].pb(i);
	}
	int find(int x) {
		return fa[x] == x ? x : fa[x] = find(fa[x]);
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	void merge(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return ;
		if (v[x].size() < v[y].size()) swap(x, y);
		for (int i = 0; i < v[y].size(); ++ i) v[x].pb(v[y][i]);
		fa[y] = x;
	}
} dsu;

const int maxn = 2e5 + 5;
int n, d, a[maxn];

int main() {
	scanf("%d %d", &n, &d);
	for (int i = 0; i < n; ++ i)
		scanf("%d", &a[i]);
	dsu.init();
	seg0.init(); seg1.init();
	for (int i = 0; i < n; ++ i) {
		seg0.upd(i, a[i] - 1LL * d * i);
		seg1.upd(i, a[i] + 1LL * d * i);
	}
	ll ans = 0;
	while (dsu.v[dsu.find(0)].size() != n) {
		vector <pair <ll, pair <int, int> > > e;
		for (int i = 0; i < n; ++ i) {
			if (dsu.find(i) == i) {
//				eprintf("%d\n", i);
				for (int j = 0; j < dsu.v[i].size(); ++ j) {
					int x = dsu.v[i][j];
//					eprintf("%d ", x);
					seg0.upd(x, linf);
					seg1.upd(x, linf);
				}
//				eprintf("\n");
				pair <ll, pair <int, int> > mn = mp(linf, mp(-1, -1));
				for (int j = 0; j < dsu.v[i].size(); ++ j) {
					int x = dsu.v[i][j];
					pair <ll, int> to = seg0.qry(0, x);
					to.first += a[x] + 1LL * d * x;
					mn = min(mn, mp(to.first, mp(x, to.second)));
				}
				for (int j = 0; j < dsu.v[i].size(); ++ j) {
					int x = dsu.v[i][j];
					pair <ll, int> to = seg1.qry(x + 1, n);
					to.first += a[x] - 1LL * d * x;
					mn = min(mn, mp(to.first, mp(x, to.second)));
				}
				e.pb(mn);
				for (int j = 0; j < dsu.v[i].size(); ++ j) {
					int x = dsu.v[i][j];
					seg0.upd(x, a[x] - 1LL * d * x);
					seg1.upd(x, a[x] + 1LL * d * x);
				}
			}
		}
		for (int i = 0; i < e.size(); ++ i) {
			int u = e[i].second.first;
			int v = e[i].second.second;
			ll cost = e[i].first;
			if (!dsu.same(u, v)) {
				dsu.merge(u, v);
				ans += cost;
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;

const int MAXN = 400100;
vector<PII> graph[MAXN];

void add_edge(int v, int u, int c) {
  graph[v].push_back(PII(u,c));
  graph[u].push_back(PII(v,c));
}

int main() {
  int N, D;
  cin >> N >> D;
  for(int i=0; i<N; i++) {
    LL p;
    cin >> p;
    add_edge(i, i+N, p);
  }

  for(int i=0; i<N-1; i++) {
    int v,u,c;
    //cin >> v >> u >> c;
    //v--;u--;
    add_edge(i, i+1, D);
  }

  priority_queue<pair<LL,PII> , vector<pair<LL,PII> >, greater<pair<LL,PII> > > pq;
  vector<int> used(2*N, 0), dist(2*N, 0);
  int cnt = 1;
  LL ans = 0;
  for(int i=0; i<N; i++) {
    pq.push(make_pair(0, PII(i+N, -1)));
  }
  while(!pq.empty()) {
    auto cur = pq.top(); pq.pop();
    LL v = cur.second.first;
    if(used[v]) {
      LL u = cur.second.second;
      if(used[v] > used[u])
	ans += dist[v] + cur.first;
      continue;
    }
    used[v] = cnt;
    cnt++;
    dist[v] = cur.first;
    for(auto uc: graph[v]) {
      LL u = uc.first;
      LL c = uc.second;
      pq.push(make_pair(dist[v] + c, PII(u, v)));
    }

  }
  cout << ans << endl;

  return 0;
}


#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

constexpr int64_t MOD = 1e9+7;

int main() {
  int N;
  cin >> N;

  vector<int64_t> nums(N);
  for (int n = 0; n < N; ++n) {
    cin >> nums[n];
  }
  sort(nums.begin(), nums.end());

  vector<vector<int64_t>> cnt(2, vector<int64_t>(61));
  for (int64_t n : nums) {
    bitset<61> bs(n);
    for (size_t i = 0; i <= 60; ++i) {
      if (bs.test(i)) {
        ++cnt[1][i];
      } else {
        ++cnt[0][i];
      }
    }
  }
  int64_t result = 0;
  for (size_t i = 0; i <= 60; ++i) {
    result += (static_cast<int64_t>(pow(2, i)) % MOD) * (cnt[0][i] * cnt[1][i] % MOD);
    result %= MOD;
  }
  cout << result << endl;

  return 0;
}


#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x)
#define debug(x)
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	int n;
	while(cin>>n,n){
		rep(i,n){
			vint v(3);
			rep(j,3) cin>>v[j];
			vint w=v;
			sort(ALL(w));
			if(w[2]==100) cout<<"A"<<endl;
			else if(v[0]+v[1]>=180) cout<<"A"<<endl;
			else if(v[0]+v[1]+v[2]>=240) cout<<"A"<<endl;
			else if(v[0]+v[1]+v[2]>=210) cout<<"B"<<endl;
			else if(v[0]+v[1]+v[2]>=150&&max(v[0],v[1])>=80) cout<<"B"<<endl;
			else cout<<"C"<<endl;
		}
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(0);
  	cout<<fixed<<setprecision(20);
    mainmain();
}

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<utility>

using namespace std;

int n;

char student[10010];

double cal(int m,int e,int j)
{
	double ave = (double)(m + e + j) / 3;

	return ave;
}

int main(void)
{
	while (cin >> n, n)
	{
		for (int i = 0; i < n; i++)
		{
			int m, e, j;

			cin >> m >> e >> j;

			if (m==100||e==100||j==100)
			{
				student[i] = 'A';

				continue;
			}
			if (((double)(m+e)/2)>=90)
			{
				student[i] = 'A';

				continue;
			}

			if (cal(m,e,j)>=80)
			{
				student[i] = 'A';

				continue;
			}

			if (cal(m, e, j) >= 70)
			{
				student[i] = 'B';

				continue;
			}

			if (cal(m, e, j) >= 50)
			{
				if (m>=80||e>=80)
				{
					student[i] = 'B';

					continue;
				}
			}

			student[i] = 'C';

		}

		for (int i = 0; i < n; i++)
		{
			cout << student[i] << endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

long long int n,i,x,a;
string s,t;

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin>>s>>t;
	n=s.size();
	for (i=0;i<n;i++) t.push_back(s[i]);
	cout<<t;
}

#include <stdio.h>
int main ()
{
char a[200], b[200];
scanf("%s %s", a, b) ;
printf("%s%s\n", b, a) ;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int N;
	while ( cin >> N ) {
		if ( N == 0 ) {
			break;
		}
		typedef pair<double, string> P;
		vector<P> ans;
		while ( N-- ) {
			string l;
			int p;
			cin >> l >> p;
			int t = 0;
			int d = 0;
			for ( int i = 0; i < 5; i++ ) {
				int a;
				cin >> a;
				if ( i <= 2 ) t += a;
				else d += a;
			}
			int f, s, m;
			int sum = 0;
			cin >> f >> s >> m;

			t += d*m;
			sum = f*s*m;
			ans.push_back(P(-((double)(sum-p)/(double)t), l));
		}
		sort(ans.begin(), ans.end());

		for ( int i = 0; i < ans.size(); i++ ) {
			cout << ans[i].second << endl;
		}
		cout << '#' << endl;
	}
	return 0;
}

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  while(cin >> N, N){
	vector< pair<double,string> > k;
	REP(i,N){
	  string L; int P, A, B, C, D, E, F, S, M;
	  cin >> L >> P >> A >> B >> C >> D >> E >> F >> S >> M;
	  int tot = A + B + C + D + E + (M - 1)*(D + E);
	  int pr = F * S * M - P;
	  k.PB(MP(pr*1.0/tot, L));
	}
	sort(ALL(k), [](const pair<double,string>& p1, const pair<double,string>& p2)->bool{
		return p1.first > p2.first || (abs(p1.first-p2.first) < EPS
									   && p1.second < p2.second);
	  });
	REP(i,N)
	  cout << k[i].second << endl;
	cout << "#" << endl;
  }

  return 0;
}