A. Valid Integer

A. Valid Integer

Time Limit: 0.5 s

Memory Limit: 256.0 MB

Description

You are given two positive integers x and y.

  • Your task is to find any positive integer k such that:

    • 1 ≤ k ≤ 100
    • k is not divisible by x
    • k is not divisible by y

If no such integer exists, print -1.

Input

  • The first line contains an integer t (1 ≤ t ≤ 1000) — the number of test cases.

  • Each of the next t lines contains two integers x and y (1 ≤ x, y ≤ 100).

Output

  • For each test case, print one integer:

    • Any integer k (1 ≤ k ≤ 100) that is not divisible by both x and y

    • Print -1 if no such integer exists

Sample

Input Output
5
2 4
2 3
40 5
1 100
20 14
17
31
12
-1
99
  • First test case : 17 is a Valid Answer.
    • 17 % 2 ≠ 0 → not divisible by 2
    • 17 % 4 ≠ 0 → not divisible by 4
    • 17 lies in the range 1 to 100
      So, 17 satisfies all conditions and is a valid answer.
      Note: There are also other valid answers. (ex. 19,13,23 etc).

Information

ID
1235
Difficulty
1
Category
Beginners | Math Click to Show
Tags
# Submissions
120
Accepted
78
Accepted Ratio
65%
Uploaded By

Related

In following contests:

Happy New Year 2026