cho.sh
Notes
Loading...

Absolute Value Sequence

Time limit

2s

Memory limit

128 MB

Problem

An infinite sequence S is defined as follows.

  • S_0 = first
  • S_1 = second
  • S_i = |S_{i-2} - S_{i-1}| for i >= 2

You are given first, second, and the number of queries N. For each query index i, output the value of S_i.

Input

The first line contains first, second, and the number of queries N.

Each of the next N lines contains one query. A query is an integer i, and its answer is S_i.

N is a positive integer no greater than 50. first, second, and every query index i are non-negative integers no greater than 10^18.

Output

For each query, output S_i on its own line, in the same order as the input queries.