# coding: utf-8 # Your code here! T=int(input()) for _ in range(T): A,B,K=map(int,input().split()) high=3*10**18 low=-1 while high-low>1: middle=(high+low)//2 yaku_A=middle//A yaku_B=middle//B yaku_AB=middle//(A*B) all_unyaku=middle-yaku_A-yaku_B+yaku_AB if all_unyaku>=K: high=middle else: low=middle print(high)