from sys import stdin import math def input(): return stdin.readline() def main(): T = int(input()) for _ in range(T): a, b, k = map(int, input().split()) l = 1 r = 3 * 10**18 while l < r: mid = l + (r - l) // 2 count = mid - mid // a - mid // b + mid // (a * b // math.gcd(a, b)) if count < k: l = mid + 1 else: r = mid print(l) if __name__ == "__main__": main()