#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[]){
	_position += _a_dice * _eaction;
	return _position + _N[_position];
}

bool isConnected(int _position, int _dice, 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[_dice][_lr]) return false;
	_is_checked[_position].dice[_dice][_lr] = true;

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

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

	memo_t tmp;
	tmp.dice = _dice;
	tmp.direction = direction;
	_route.push_back(tmp);
	
	if(_position == _s) return true;

	for(int m=1; m<=_M; m++){
		if(_position - m == _N[m]){
			for(int dice=1; dice<=NumberOfFaces; dice++){
				for(int lr=0; lr<2; lr++){
					if(isConnected(m, dice, lr, _a, _is_checked, _N, _M, _route, _s)) return true;
				}
			}
		}
	}

	_route.pop_back();
	
	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 dice=1; dice<=NumberOfFaces; dice++){
	for(int lr=0; lr<2; lr++){
		is_checked[m].dice[dice][lr] = false;
	}}}

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

	for(int dice=1; dice<=NumberOfFaces; dice++){
		for(int lr=0; lr<2; lr++){
			if(isConnected(position, dice, 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 dice=1; dice<=NumberOfFaces; dice++) cin >> a[dice];
	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 position = s;
	vector<int> memo;
	memo.push_back(s);
	for(int i=route.size()-1; i>=0; i--){
		position = move(position, a[route[i].dice], route[i].direction, N);
		memo.push_back(position);
	}
	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();
	}

	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: 1532