T = int(input()) for case in range(T): d,A,B = map(int,input().split()) oriA = A+0 a = 0 while A > 0: a += A%d A = A//d if A == 0 and a >= d: A = a a = 0 #print(a) num = B-oriA+1 loop_num = num//(d-1) amari = num%(d-1) loop_wa = (1+d-1)*(d-1)//2 if a + amari-1 >= d: #先頭に戻る amari_wa = loop_wa - ((a-1) + (a-(d-1-amari)))*(d-1-amari)//2 else: amari_wa = (a + a + amari-1)*amari//2 ans = loop_num*loop_wa + amari_wa #print(loop_num,amari,loop_wa,amari_wa) print(ans)