#include <iostream>
#include <vector>

using namespace std;

const int LimitOfGridNumber = 300, NumberOfFaces = 6, MaxTurn = 3000;

enum EAction{
	Right = 1,
	Stay = 0,
	Left = -1,
};

typedef struct{
	int dice;
	EAction direction;
} memo_t;

typedef struct{
	bool dice[NumberOfFaces+1][2];
} check_t;

int move(int _position, int _a_dice, EAction _eaction, const int _N[]){
	int pos = _position + _a_dice * _eaction;
	return pos += _N[pos];
}

bool isConnected(int _position, int _f, int _lr, const int _a[], check_t _is_checked[], const int _N[], int _M, vector<memo_t> &_route, int _s){
	if(_is_checked[_position].dice[_f][_lr]) return false;
	_is_checked[_position].dice[_f][_lr] = true;

	EAction direction;
	if(_lr == 0) direction = Right;
	else direction = Left;

	_position -= _a[_f] * direction;
	if(_position < 1 || _position > _M) return false;
	if(_route.size() >= MaxTurn) return false;

	memo_t tmp;
	tmp.dice = _f;
	tmp.direction = direction;
	_route.push_back(tmp);

	//cout << "dice:" << tmp.dice << " direction:" << tmp.direction << endl;
	//cout << _route.size() << endl;
	//return true;
	
	if(_position == _s) return true;

	for(int m=1; m<=_M; m++){
		if(_position - m == _N[m]){
			//cout << "dice:" << tmp.dice << " direction:" << tmp.direction << " m:" << m << endl;
			for(int f=1; f<=NumberOfFaces; f++){
				for(int lr=0; lr<2; lr++){
					if(isConnected(m, f, lr, _a, _is_checked, _N, _M, _route, _s)) return true;
				}
			}
		}
	}

	_route.pop_back();
	
	//cout << "ok" << endl;
	return false;
}

void FindRoute(int _M, const int _a[], int _s, int _g, const int _N[], vector<memo_t> &_route){
	check_t is_checked[LimitOfGridNumber+1];
	for(int m=1; m<=_M; m++){
	for(int f=1; f<=NumberOfFaces; f++){
	for(int lr=0; lr<2; lr++){
		is_checked[m].dice[f][lr] = false;
	}}}

	int position = _g;
	
	for(int m=1; m<=_M; m++){
		if(position - m == _N[m]){
			for(int f=1; f<=NumberOfFaces; f++){
				for(int lr=0; lr<2; lr++){
					if(isConnected(m, f, lr, _a, is_checked, _N, _M, _route, _s)) return;
				}
			}
		}
	}

	for(int f=1; f<=NumberOfFaces; f++){
		for(int lr=0; lr<2; lr++){
			if(isConnected(position, f, lr, _a, is_checked, _N, _M, _route, _s)) return;
		}
	}
}

int main(){
	int M, a[NumberOfFaces+1], s, g, N[LimitOfGridNumber+1];
	cin >> M;
	for(int f=1; f<=NumberOfFaces; f++) cin >> a[f];
	cin >> s >> g;
	for(int m=1; m<=M; m++) cin >> N[m];

	vector<memo_t> route;

	FindRoute(M, a, s, g, N, route);
	int clear_turn = route.size();

	int test = s;
	vector<int> memo;
	memo.push_back(s);
	for(int i=route.size()-1; i>=0; i--){
		test = move(test, a[route[i].dice], route[i].direction, N);
		memo.push_back(test);
		//cout << "a[" << route[i].dice << "]:" << a[route[i].dice] << "\tLeft or Right:" << route[i].direction << "\tm:" << test << endl;
	}
	for(int turn=0; turn<=clear_turn; turn++){
		for(int t=0; t<turn; t++){
			if(memo[t] == memo[turn]){
				route.erase(route.end()-turn, route.end()-t);
				memo.erase(memo.begin()+t, memo.begin()+turn);
				turn=t;
				break;
			}
		}
		clear_turn = route.size();
	}

	/*
	test = s;
	for(int i=route.size()-1; i>=0; i--){
		test = move(test, a[route[i].dice], route[i].direction, N);
		cout << "a[" << route[i].dice << "]:" << a[route[i].dice] << "\tLeft or Right:" << route[i].direction << "\tm:" << test << endl;
	}
	//exit(1);
	//*/

	int position = s;
	int index = clear_turn - 1;
	for(int turn=0; turn<MaxTurn; turn++){
		int dice;
		cin >> dice;

		memo_t tmp = route[index];
		EAction eaction = Stay;
		if(dice == tmp.dice){
			eaction = tmp.direction;
			index--;
		}

		cout << eaction << endl;
		cout.flush();

		// 移動の処理
		if(eaction != Stay) position = move(position, a[dice], eaction, N);
		
		// クリア判定 -> クリアなら break
		if(position == g) return 0;
	}
	return 0;
}

Measured memory_bytes: 1528