Alice is teaching Bob maths via a game called N-guesser.

Alice has a positive integer N which Bob needs to guess. She gives him two pieces of information with which to do this:

A positive integer X, which denotes the sum of divisors of N.
Two positive integers A and B, which denote that the sum of reciprocals of divisors of N is A/B.

Bob either needs to guess N or tell that no such number exists.

It can be shown that if a valid N exists, it is unique.

------ Input Format ------ 

- The first line of input contains a single integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, containing three space-separated integers X, A, B.

------ Output Format ------ 

For each test case, output a new line containing the answer — Alice's number N, or -1 if no such number exists.

------ Constraints ------ 

$1 ≤ T ≤ 1000$
$1 ≤ X ≤ 10^{9}$
$1 ≤ A, B ≤ 10^{9}$
$\gcd(A, B) = 1$

----- Sample Input 1 ------ 
2
4 4 3
4 1 1

----- Sample Output 1 ------ 
3
-1
----- explanation 1 ------ 
Test case $1$: The divisors of $3$ are $1$ and $3$. Their sum is $4$ and the sum of their reciprocals is $4/3$.

Test case $2$: It can be proved that no positive integer $N$ exists whose divisors sum to $4$ and reciprocals of divisors sum to $1$.

Difficulty: MEDIUM_HARD

Solutions:
t = int(input())
while t != 0:
	l = list(map(int, input().split()))
	a = l[0]
	b = l[1]
	c = l[2]
	if b / c <= 1:
		if a == 1:
			print('1')
			t = t - 1
			continue
		else:
			print('-1')
			t = t - 1
			continue
	print(int(a * c / b))
	t = t - 1


for _ in range(int(input())):
	(n, m, k) = map(int, input().split())
	res = n * k // m
	if m <= k and n != 1:
		print('-1')
	else:
		print(res)


t = int(input())
for _ in range(t):
	(x, a, b) = map(int, input().split(' '))
	n = x * b // a
	if a <= b and x != 1:
		print(-1)
	else:
		print(n)


from math import sqrt
t = int(input())
for i in range(t):
	(x, a, b) = map(int, input().split())
	if x % a == 0:
		p = x // a
		d = p * b
		s = 0
		for j in range(1, int(sqrt(d) + 1)):
			if s > x:
				break
			if d % j == 0:
				s += j
				if d // j != j:
					s += d // j
		if s != x:
			print(-1)
		else:
			print(d)
	else:
		print(-1)


import sys
input = sys.stdin.readline
import math

def printDivisors(n, val):
	i = 1
	sum1 = 0
	while i <= math.sqrt(n) and sum1 < val:
		if n % i == 0:
			if n / i == i:
				sum1 += i
			else:
				sum1 += i
				sum1 += int(n / i)
		i = i + 1
	return sum1
t = int(input())
while t:
	t -= 1
	(n, a, b) = map(int, input().split())
	ans = b * n / a
	if ans == int(ans):
		s1 = printDivisors(int(ans), n)
		if s1 == n:
			sys.stdout.write(str(int(ans)) + '\n')
		else:
			sys.stdout.write(str(-1) + '\n')
	else:
		sys.stdout.write(str(-1) + '\n')


from math import sqrt
for _ in range(int(input())):
	(X, A, B) = map(int, input().split())
	if X % A == 0:
		P = X // A
		den = P * B
		Sum = 0
		for i in range(1, int(sqrt(den) + 1)):
			if Sum > X:
				break
			if den % i == 0:
				Sum += i
				if den // i != i:
					Sum += den // i
		if Sum != X:
			print(-1)
		else:
			print(den)
	else:
		print(-1)


import math
for i in range(int(input())):
	(x, a, b) = [int(x) for x in input().split()]
	x1 = x * b / a
	if x == 1 and a // b == 1:
		print(1)
	elif a / b <= 1:
		print(-1)
	else:
		print(int(x1))


import sys
import bisect
from bisect import bisect_left as lb
from bisect import bisect_right as rb
from queue import PriorityQueue
from queue import Queue
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
import random
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs2(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
a = []
(n, k) = (0, 0)
b = []
vis = []
tot = 0
time = []
time1 = []
adj = []
mx = -1
eps = 1e-07
gp = []
ans = []

def update_it(bit, i, val):
	n = len(bit)
	while i < n:
		bit[i] += val
		i += i & -i

def get_ans(bit, i):
	n = len(bit)
	tot = 0
	while i > 0:
		tot += bit[i]
		i -= i & -i
	return tot

def flip(a, l, r):
	for i in range(l, r):
		a[i] = '0' if a[i] == '1' else '1'
	return

class Disjoint_SU:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.size = [1 for i in range(n)]

	def lake_de(self, a):
		if a == self.parent[a]:
			return a
		self.parent[a] = self.lake_de(self.parent[a])
		return self.parent[a]

	def jod(self, a, b):
		x = self.lake_de(a)
		y = self.lake_de(b)
		if x == y:
			return True
		if self.size[x] > self.size[y]:
			self.size[x] += self.size[y]
			self.parent[y] = x
		else:
			self.size[y] += self.size[x]
			self.parent[x] = y
		return False

def hnbhai(tc):
	(x, a, b) = sd()
	n = b * x // a
	if b * x % a != 0:
		print(-1)
		return
	if a < b:
		print(-1)
		return
	sm = 0
	p = 1
	while p * p <= n:
		if n % p == 0:
			sm += p
			if n // p != p:
				sm += n // p
		p += 1
	if sm != x:
		print(-1)
		return
	print(n)
	return
for _ in range(sb()):
	hnbhai(_ + 1)


import math

def div_sum(n):
	s = 0
	for i in range(1, int(pow(n, 0.5)) + 1):
		if n % i == 0:
			s += i
			if i != n // i:
				s += n // i
	return s
for _ in range(int(input())):
	(x, a, b) = list(map(int, input().split()))
	if x * b % a != 0 or a < b:
		print(-1)
	else:
		g = x * b // a
		if div_sum(g) == x:
			print(g)
		else:
			print(-1)


import math

def divSum(n):
	if n == 1:
		return 1
	result = 0
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result = result + i
			else:
				result = result + (i + n // i)
	return result + n + 1
t = int(input())
for tc in range(t):
	(x, a, b) = map(int, input().split())
	if x % a != 0 or b > a:
		print(-1)
		continue
	b = b * (x // a)
	if divSum(b) == x:
		print(b)
	else:
		print(-1)


import math
t = int(input())
for i in range(t):
	l = [int(n) for n in input().split()]
	x = l[0]
	a = l[1]
	b = l[2]
	if x == a:
		print(b)
	elif a <= b:
		print(-1)
	else:
		print(x // a * b)


def div(num):
	s = 0
	for i in range(1, int(num ** 0.5) + 1):
		if num % i == 0:
			s += i
			if num // i != i:
				s += num // i
	return s
for _ in range(int(input())):
	(x, a, b) = list(map(int, input().split()))
	if a < b:
		print(-1)
	elif x * b % a == 0:
		n = x * b // a
		s = div(n)
		if x == s:
			print(n)
		else:
			print(-1)
	else:
		print(-1)


for _ in range(int(input())):
	(x, a, b) = map(int, input().split())
	if a == b:
		if x == 1:
			ans = 1
		else:
			ans = -1
	elif a < b:
		ans = -1
	elif x == a:
		ans = b
	else:
		ans = b * (x // a)
	print(ans)


T = int(input())
for K in range(T):
	y = list(map(int, input().split()))
	(x, a, b) = (y[0], y[1], y[2])
	if a < b:
		print(-1)
	elif x * b % a == 0:
		c = x * b // a
		s = 0
		for i in range(1, int(c ** 0.5) + 1):
			if c % i == 0:
				s += i
				if c // i != i:
					s += c // i
		if x == s:
			print(c)
		else:
			print(-1)
	else:
		print(-1)


tc = int(input())

def divisors(n):
	s = set()
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			s.add(i)
			s.add(n // i)
	return s
for _ in range(tc):
	(x, a, b) = map(int, input().split())
	if a < b:
		print(-1)
	else:
		n = x * b // a
		divisros_n = divisors(n)
		if sum(divisros_n) == x:
			print(n)
		else:
			print(-1)


from collections import Counter, deque

def ga():
	return list(map(int, input().split()))
for _ in range(int(input())):
	(x, a, b) = ga()
	if x == 1 and a == 1 and (b == 1):
		print(1)
	elif x * b % a == 0:
		cand = x * b // a
		if cand >= x:
			print(-1)
		else:
			print(cand)
	else:
		print(-1)


import math

def Factor_Sum(num1, num2):
	sum = 0
	for i in range(1, int(math.sqrt(num1)) + 1):
		if sum > num2:
			break
		elif num1 % i == 0:
			sum += i
			if num1 // i != i:
				sum += num1 // i
	return sum

def main():
	for __ in range(int(input())):
		(x, a, b) = map(int, input().split())
		if x % a == 0:
			p = x * b / a
			res = Factor_Sum(p, x)
			if res == x:
				print(int(p))
			else:
				print(-1)
		else:
			print(-1)
main()


import sys

def input():
	return sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(x, a, b) = map(int, input().split())
	if a / b < 1:
		print(-1)
		continue
	if x % a > 0:
		print(-1)
		continue
	n = b * (x // a)
	y = []
	ct = 0
	while n % 2 == 0:
		n //= 2
		ct += 1
	if ct > 0:
		y.append([2, ct])
	i = 3
	while i <= n ** 0.5:
		ct = 0
		while n % i == 0:
			n //= i
			ct += 1
		if ct > 0:
			y.append([i, ct])
		if n == 1:
			break
		i += 2
	if n > 1:
		y.append([n, 1])
	tmp = 1
	for i in range(len(y)):
		p = y[i][0]
		r = y[i][1]
		tmp *= (1 - p ** (r + 1)) // (1 - p)
	if tmp == x:
		print(b * (x // a))
	else:
		print(-1)


from functools import reduce
t = int(input())
while t > 0:
	(x, a, b) = map(int, input().split())
	fa = int(x / a)
	ans = fa * b
	summ = 0
	mid = int(ans ** 0.5)
	i = 1
	if a >= b and x % a == 0:
		while i <= mid:
			if ans % i == 0:
				summ += i
				if int(ans / i) != i:
					summ += int(ans / i)
			i += 1
		if summ == x:
			print(ans)
		else:
			print(-1)
	else:
		print(-1)
	t -= 1


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(x, a, b) = map(int, input().split())
	n = x * b // a
	if a == b and x == 1:
		sys.stdout.write(str(1) + '\n')
	elif b >= a:
		sys.stdout.write(str(-1) + '\n')
	else:
		sys.stdout.write(str(n) + '\n')


t = int(input())
for i in range(t):
	(x, a, b) = map(int, input().split())
	if x == 1 and a == b:
		print('1')
	elif x % a != 0 or b >= a:
		print('-1')
	else:
		print(int(x * b / a))


for i in range(int(input())):
	(x, a, b) = map(int, input().split())
	j = 0
	n = x * b // a
	if n > x:
		print(-1)
	elif a <= b and x != 1:
		print(-1)
	else:
		print(n)


import math
t = int(input())
for t in range(t):
	(x, a, b) = map(int, input().split())
	num = x * b / a
	if num % 1 != 0:
		print(-1)
	if num % 1 == 0:
		check = True
		sum = 0
		num = x * b // a
		for i in range(1, int(math.sqrt(num)) + 1):
			if num % i == 0:
				sum = sum + i
				if num // i != i:
					sum = sum + num // i
				if sum > x:
					check = False
					break
		if sum == x:
			print(num)
		elif check == False or sum != x:
			print(-1)


import math
for _ in range(int(input())):
	(x, a, b) = map(int, input().split())
	if x != a:
		c = x // a
		a *= c
		b *= c
	count = 0
	q = math.sqrt(b)
	r = True
	for i in range(1, int(q) + 1):
		if b % i == 0:
			count = count + i
			if b // i != i:
				count += b // i
			if count > x:
				r = False
				break
	if count == x:
		print(b)
	elif r == False or count != x:
		print(-1)


import math as m
for i in range(int(input())):
	(x, a, b) = map(int, input().split())
	q = x // a
	a *= q
	b *= q

	def sumofFactors(b, x):
		summ = 0
		i = 1
		for i in range(1, int(m.sqrt(b)) + 1):
			if b % i == 0:
				q = b // i
				summ += i
				if q != i:
					summ += q
		return int(summ) == x
	if x == a and a >= b and sumofFactors(b, x):
		print(b)
	else:
		print(-1)


t = int(input())
for _ in range(t):
	(x, a, b) = map(int, input().split())
	if x < a / b or x < x // a * b or x % a != 0:
		print(-1)
		continue
	ans = x // a * b
	s = 0
	for i in range(1, int(ans ** 0.5) + 1):
		if ans % i == 0:
			if ans // i == i:
				s += i
			else:
				s += ans // i + i
	if s == x:
		print(ans)
	else:
		print(-1)


def isit(x):
	ans = 0
	for i in range(1, int(x ** (1 / 2)) + 1):
		if x % i != 0:
			continue
		ans += i
		if x / i != i:
			ans += x / i
	return ans
for _ in range(int(input())):
	(x, a, b) = map(int, input().split())
	if x * b % a != 0 or a < b:
		print(-1)
		continue
	else:
		gue = x * b // a
		if x == isit(gue):
			print(gue)
		else:
			print(-1)


t = int(input())
for _ in range(t):
	(x, a, b) = map(int, input().split(' '))
	j = 0
	n = x * b // a
	if n != int(n) or n > x:
		print(-1)
	elif a <= b and x != 1:
		print(-1)
	else:
		print(n)


t = int(input())
while t != 0:
	(x, A, B) = map(int, input().split())
	net = B * x // A
	if B * x % A != 0:
		print(-1)
	elif A <= B and x != 1:
		print(-1)
	else:
		print(net)
	t -= 1


for _ in range(int(input())):
	(x, a, b) = [int(x) for x in input().split()]
	if x * b % a != 0 or (a <= b and x != 1):
		print(-1)
	else:
		print(x * b // a)


for _ in range(int(input())):
	(x, a, b) = [int(x) for x in input().split()]
	n = x * b / a
	if x % a != 0 or n > 1000000000.0 or a < b:
		print(-1)
		continue
	n = int(n)
	s1 = 0
	i = 1
	while i * i <= n:
		if n % i == 0:
			if i * i == n:
				s1 += i
			else:
				s1 += i + n // i
		i += 1
	if s1 == x:
		print(n)
	else:
		print(-1)


T = int(input())
for i in range(T):
	(X, A, B) = input().split()
	X = int(X)
	A = int(A)
	B = int(B)
	if X == 1:
		print(1)
	elif A <= B:
		print(-1)
	else:
		print(int(X * B / A))


import math

def solve(x, a, b):
	if x % a == 0:
		t = x // a
		factor = b * t
		s = 0
		for i in range(1, int(math.sqrt(factor)) + 1):
			p = factor % i
			q = factor // i
			if s > x:
				break
			if p == 0:
				s += i
				if q != i:
					s += factor // i
		if s != x:
			return -1
		else:
			return factor
	else:
		return -1
t = int(input())
for i in range(t):
	(X, A, B) = map(int, input().split())
	print(solve(X, A, B))


T = int(input())
for t in range(0, T):
	(X, A, B) = map(int, input().split(' '))
	term = X * B / A
	if A == B and X == 1:
		print(1)
	elif B >= A:
		print(-1)
	else:
		print(int(term))


for each in range(int(input())):
	(x, a, b) = map(int, input().split(' '))
	if x == 1 and a == 1 and (b == 1):
		print(1)
	elif a <= b:
		print(-1)
	elif x % a != 0:
		print(-1)
	else:
		print(x // a * b)


for _ in range(int(input())):
	(x, a, b) = map(int, input().split())
	print(1 if x == a == b == 1 else -1 if x % a or a <= b else b * (x // a))


import math

def prime(n):
	s = 0
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			s += i
			if n // i != i:
				s += n // i
	return s
for t in range(int(input())):
	(x, a, b) = map(int, input().split())
	if x * b % a != 0 or a < b:
		print(-1)
	else:
		n = x * b // a
		if prime(n) == x:
			print(n)
		else:
			print(-1)


def solver(x, a, b):
	if x == 1 and a == b:
		expected = 1
	elif x * b % a != 0 or b >= a:
		expected = -1
	else:
		expected = x * b // a
	print(expected)
t = int(input())
while t > 0:
	t -= 1
	(x, a, b) = list(map(int, input().split(' ')))
	solver(x, a, b)


def solver(x, a, b):
	if x * b % a != 0 or a < b:
		print('-1')
	else:
		expected = x * b // a
		sum = 0
		for i in range(1, int(expected ** 0.5) + 1):
			if expected % i == 0:
				sum += i
				if expected // i != i:
					sum += expected // i
		if sum == x:
			print(expected)
		else:
			print('-1')
t = int(input())
while t > 0:
	t -= 1
	(x, a, b) = list(map(int, input().split(' ')))
	solver(x, a, b)


for _ in range(int(input())):
	(x, a, b) = map(int, input().split())
	v = x * b / a
	if a == 1:
		if x == 1 and b == 1:
			print(1)
		else:
			print(-1)
	elif v == int(v):
		print(int(v))
	else:
		print(-1)


import math
for tc in range(int(input())):
	ls = list(map(int, input().split()))
	(X, A, B) = (ls[0], ls[1], ls[2])
	if X * B % A == 0:
		ans = X * B // A
		su = 0
		fl = True
		for x in range(1, int(math.sqrt(ans)) + 1):
			if ans % x == 0:
				if x * x != ans:
					su += x
					su += ans // x
				else:
					su += x
				if su > X:
					fl = False
					break
		if fl == False:
			print(-1)
		elif X == su:
			print(ans)
		else:
			print(-1)
	else:
		print(-1)


def check_sum(n, x):
	s = 0
	i = 1
	while i * i < n:
		if n % i == 0:
			s += n // i + i
		i += 1
	if i * i == n:
		s += i
	return s == x
test = int(input())
while test:
	(x, a, b) = map(int, input().split())
	print(-1) if x * b % a != 0 or a < b else print(x * b // a) if check_sum(x * b // a, x) else print(-1)
	test -= 1


for _ in range(int(input())):
	(x, a, b) = map(int, input().split())

	def getsumDivisor(n):
		import math
		sum_val = 0
		sq_n = int(math.sqrt(n) + 1)
		for i in range(1, sq_n):
			if n % i == 0:
				sum_val += i
				if n // i != i:
					sum_val += n // i
		return sum_val
	if a < b or x * b % a != 0:
		print(-1)
	else:
		guess = x * b // a
		if getsumDivisor(guess) == x:
			print(guess)
		else:
			print(-1)


import sys, os.path, math
if os.path.exists('Input.txt'):
	sys.stdin = open('Input.txt', 'r')
	sys.stdout = open('Output.txt', 'w')
T = int(input())
for _ in range(T):
	(X, A, B) = map(int, input().split())
	Value = X * B / A
	if A == 1:
		if X == 1 and B == 1:
			print(1)
		else:
			print(-1)
	elif Value == int(Value):
		print(int(Value))
	else:
		print(-1)


import itertools
import collections, math
from collections import defaultdict
from collections import Counter
for t in range(int(input())):
	(x, a, b) = [int(x) for x in input().split()]
	n = x * b
	if n % a != 0:
		print(-1)
		continue
	n = n // a
	if x == 1 and a == 1 and (b == 1):
		print(1)
		continue
	if x > n:
		print(n)
	else:
		print(-1)


from bisect import bisect_left
from typing import DefaultDict
from collections import OrderedDict, defaultdict
import math
from math import sqrt
import collections
from sys import maxsize
from itertools import combinations_with_replacement
import sys

def sieve_erasthones(n):
	cnt = 0
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p += 1
	prime[0] = False
	prime[1] = False
	for p in range(n + 1):
		if prime[p]:
			cnt += 1
	return cnt

def calculate(p, q):
	mod = 998244353
	expo = 0
	expo = mod - 2
	while expo:
		if expo & 1:
			p = p * q % mod
		q = q * q % mod
		expo >>= 1
	return p

def count_factors(n):
	i = 1
	c = 0
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				c += 1
			else:
				c += 2
		i += 1
	return c

def ncr_modulo(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def isprime(n):
	prime_flag = 0
	if n > 1:
		for i in range(2, int(sqrt(n)) + 1):
			if n % i == 0:
				prime_flag = 1
				break
		if prime_flag == 0:
			return True
		else:
			return False
	else:
		return True

def smallestDivisor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i * i <= n:
		if n % i == 0:
			return i
		i += 2
	return n

def dict_ele_count(l):
	d = DefaultDict(lambda : 0)
	for ele in l:
		d[ele] += 1
	return d

def max_in_dict(d):
	maxi = 0
	for ele in d:
		if d[ele] > maxi:
			maxi = d[ele]
	return maxi

def element_count(s):
	l = []
	k = s[0]
	c = 0
	for ele in s:
		if ele == k:
			c += 1
		else:
			l.append([k, c])
			k = ele
			c = 1
	l.append([k, c])
	return l

def modular_exponentiation(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 != 0:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def number_of_primefactor(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return len(set(l))

def twosum(a, n, x):
	rem = []
	for i in range(x):
		rem.append(0)
	for i in range(n):
		if a[i] < x:
			rem[a[i] % x] += 1
	for i in range(1, x // 2):
		if rem[i] > 0 and rem[x - i] > 0:
			return True
	if i >= x // 2:
		if x % 2 == 0:
			if rem[x // 2] > 1:
				return True
			else:
				return False
		elif rem[x // 2] > 0 and rem[x - x // 2] > 0:
			return True
		else:
			return False

def divSum(num):
	result = 0
	i = 2
	while i <= math.sqrt(num):
		if num % i == 0:
			if i == num / i:
				result = result + i
			else:
				result = result + (i + num / i)
		i = i + 1
	return result + 1 + num
mod = 10 ** 9 + 7
ans = 0
vowels = ['a', 'e', 'i', 'o', 'u']
for _ in range(int(input())):
	bool = True
	(x, a, b) = map(int, input().split())
	k = x // a
	if b * k == 1 and x == 1:
		print(1)
	elif a > b and divSum(b * k) == x:
		print(b * k)
	else:
		print(-1)


import math

def sol():
	(x, a, b) = list(map(int, input().split()))
	if x == 0 or a == 0 or b == 0 or (x % a != 0) or (a < b):
		print(-1)
	else:
		n = b * (x // a)
		s = 0
		for i in range(1, math.floor(math.sqrt(n)) + 1):
			if n % i == 0:
				if i == n // i:
					s += i
				else:
					s += i + n // i
		if s != x:
			print(-1)
		else:
			print(b * (x // a))
t = int(input())
for _ in range(t):
	sol()


import math
from telnetlib import DM
from traceback import print_tb
for _ in range(int(input())):
	(x, a, b) = map(int, input().split())
	if x == 1 and a == 1 and (b == 1):
		print(1)
		continue
	if b * x % a == 0:
		num = b * x // a
		if x > num:
			print(num)
		else:
			print(-1)
	else:
		print(-1)


from collections import defaultdict
t = int(input())
for i in range(t):
	(x, a, b) = list(map(int, input().split(' ')))
	if a == 1 and b == 1 and (x == 1):
		print(a)
	elif b >= a or x % a != 0:
		print(-1)
	else:
		print(x * b // a)


for i in range(int(input())):
	(x, a, b) = map(int, input().split())
	n = x * b
	if n % a != 0 or b > a:
		print(-1)
	else:
		n = n // a
		s = 0
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i * i == n:
					s += i
				else:
					s += i
					s += n // i
		if x == s:
			print(n)
		else:
			print(-1)


def sum_div(x):
	temp = 0
	ans = 1
	if x % 2 == 0:
		while x % 2 == 0:
			x = x // 2
			temp += 1
		ans *= (2 ** (temp + 1) - 1) // (2 - 1)
	for i in range(3, int(x ** 0.5) + 1):
		if x % i == 0:
			temp = 0
			while x % i == 0:
				x = x // i
				temp += 1
			ans *= (i ** (temp + 1) - 1) // (i - 1)
	if x > 1:
		ans = x + 1
	return ans
for u in range(int(input())):
	(x, a, b) = map(int, input().split())
	n = x * b
	if n % a != 0 or b > a:
		print(-1)
	else:
		n = n // a
		s = 0
		for i in range(1, int(n ** 0.5) + 1):
			if n % i == 0:
				if i * i == n:
					s += i
				else:
					s += i
					s += n // i
		if x == s:
			print(n)
		else:
			print(-1)


import math
size = input()
for _ in range(int(size)):
	failed = False
	arr = list(map(int, input().split()))
	if arr[0] % arr[1] != 0:
		print(-1)
		continue
	check = arr[0] // arr[1] * arr[2]
	ans = 0
	for i in range(1, int(check ** 0.5) + 1):
		if check % i == 0:
			(a, b) = (i, check // i)
			ans += a
			if a != b:
				ans += b
		if ans > arr[0]:
			failed = True
			print(-1)
			break
	if failed:
		continue
	if ans == arr[0]:
		print(check)
	else:
		print(-1)


from math import sqrt
t = int(input().strip())
for _ in range(t):
	(x, a, b) = list(map(int, input().strip().split()))
	n = x * b
	if n % a != 0:
		print(-1)
		continue
	n //= a
	if n > 10 ** 9:
		print(-1)
		continue
	sqrt_n = int(sqrt(n))
	s = sum((i + n // i for i in range(1, sqrt_n + 1) if n % i == 0))
	if n / sqrt_n == sqrt_n:
		s -= sqrt_n
	print(n if s == x else -1)


def solve():
	for _ in range(int(input())):
		(x, a, b) = map(int, input().split())
		if a == 1 and b == 1 and (x != 1):
			print(-1)
		elif x * b % a != 0 or a < b:
			print(-1)
		else:
			ans = x * b // a
			i = 1
			sum = 0
			while i * i <= ans:
				if ans % i != 0:
					i += 1
					continue
				sum += i
				if ans // i != i:
					sum += ans // i
				i += 1
			if sum != x:
				print(-1)
			else:
				print(ans)
solve()


def solve():
	(x, a, b) = [int(i) for i in input().split()]
	if x % a == 0 and b < a:
		return x * b // a
	if b == a and x == 1:
		return 1
	return -1
t = int(input())
for i in range(t):
	print(solve())


for ii in range(int(input())):
	(x, a, b) = map(int, input().split())
	n = b * x // a
	if a == b == x == 1:
		print(1)
	elif b * x / a == b * x // a and a > b:
		print(n)
	else:
		print(-1)


for _ in range(int(input())):
	(s, a, b) = map(int, input().split())
	r = b * s // a
	if a == b == s == 1:
		print(1)
	elif b * s / a == b * s // a and a > b:
		print(r)
	else:
		print(-1)


from math import sqrt

def SumDiv(n, x):
	Sum = 0
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			Sum += i
			if n // i != i:
				Sum += n // i
		if Sum > x:
			return False
	if Sum == x:
		return True
	return False
for _ in range(int(input())):
	(x, a, b) = map(int, input().split())
	if x == a:
		num = b
	else:
		num = x // a * b
	if SumDiv(num, x):
		print(num)
	else:
		print(-1)


try:
	t = int(input())
	j = 0
	while j < t:
		(x, a, b) = map(int, input().split())
		n = x / a * b
		if n >= x and x != 1:
			print(-1)
		else:
			print(int(n))
		j += 1
except:
	pass