logo AlgoBeat OnlineJudge
登录 注册

#209231. [SNCPC2019] K-hour Clock

内存限制:256 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

A -hour clock is a day keeping method which follows the rules below:

  • A day is divided into hours, where the -th hour is called the o' clock;
  • If it's o'clock now, it will be o'clock after hour if ;
  • If it's o'clock now, it will be o'clock after hour.

We know that it's o'clock now, and after hours it will be o'clock. What's the value of ?

输入格式

There are multiple test cases. The first line of the input is an integer (about ), indicating the number of test cases. For each test case:

The first and only line contains three integers , and (, ).

输出格式

For each test case output one line containing one integer, indicating the value of . Note that there must be . If there are multiple valid answers, you can print any of them; If there is no valid answer, print -1 (without quotes) instead.

样例

样例输入 1

4
11 18 5
3 49 4
1 9 1
1 3 10

样例输出 1

12
24
3
-1