// Author: @Drydock
use std::io::{self, Read};
fn main() {
solve();
}
fn solve() {
let mut input = String::new();
io::stdin().read_to_string(&mut input).unwrap();
let mut it = I::new(&input);
let t: usize = it.n();
let mut o = String::new();
for _ in 0..t {
let x: i32 = it.n();
let y: i32 = it.n();
let mut a = -1;
if x != 1 && y != 1 {
let mut k = 1;
while k <= 100 {
if k % x != 0 && k % y != 0 {
a = k;
break;
}
k += 1;
}
}
o.push_str(&a.to_string());
o.push('\n');
}
print!("{}", o);
}
struct I<'a> {
w: std::str::SplitWhitespace<'a>,
}
impl<'a> I<'a> {
fn new(s: &'a str) -> Self {
Self { w: s.split_whitespace() }
}
fn n<T: std::str::FromStr>(&mut self) -> T {
self.w.next().unwrap().parse().ok().unwrap()
}
}