This page is still under construction.

Parts of this page are still being built. What you see may change.

Stripes

Time limit3sMemory limit512 MB

Summary
Given stripe lengths c, z, n, decide for each board length p whether the first player wins the impartial placement game.
Level

Medium7 of 10

Topics
Game theory, Dynamic programming
Solved
No attempts yet

Problem

Stripes is a game for two players. To play it you need one board and rectangular stripes in three colors: red, green, and blue. Every red stripe has size c×1c \times 1, every green stripe z×1z \times 1, and every blue stripe n×1n \times 1, where cc, zz, and nn are positive integers. Each player has an unlimited supply of stripes of every color.

The board is a p×1p \times 1 rectangle made up of pp cells of size 1×11 \times 1.

The players move alternately. A single move consists of placing one stripe of any color on the board, subject to the following rules:

  • a stripe may not stick out of the board,
  • a stripe may not cover, even partially, any stripe that was placed earlier,
  • the two ends of a stripe must line up exactly with the cell boundaries of the board.

The player who cannot make a legal move loses. The player who moves first is called the first player. We say the first player has a winning strategy if he can always win, no matter how the second player plays.

Write a program that reads the stripe sizes and the length of one or more boards, and for each board decides whether the first player has a winning strategy.

Input

The first line contains three integers cc, zz, and nn (1≤c,z,n≤10001 \le c, z, n \le 1000), separated by single spaces: the lengths of the red, green, and blue stripes respectively.

The second line contains one integer mm (1≤m≤10001 \le m \le 1000): the number of boards to consider.

Each of the next mm lines contains one integer pp (1≤p<10001 \le p < 1000): the length of the corresponding board.

Output

Print mm lines. In the ii-th line print a single integer:

  • 11 if the first player has a winning strategy on the ii-th board,
  • 22 otherwise.

Examples1

  1. Example 1

    Input
    1 5 1
    3
    1
    5
    6
    
    Expected output
    1
    1
    2