← Home
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	if _, err := fmt.Fscan(in, &t); err != nil {
		return
	}

	for i := 0; i < t; i++ {
		var x, y, k int64
		fmt.Fscan(in, &x, &y, &k)

		if y == 1 {
			fmt.Fprintln(out, -1)
			continue
		}

		D := y - 1
		V := k - 1
		limit := int64(1000000000000)

		possible := true

		for x > 0 {
			if V >= limit {
				possible = false
				break
			}
			
			q := V / D
			if q == 0 {
				break
			}

			var steps int64 = 1
			if q < D {
				rem := (q+1)*D - 1 - V
				steps = rem / q
				if steps == 0 {
					steps = 1
				}
			}

			if steps > x {
				steps = x
			}

			V += steps * q
			x -= steps
		}

		if V >= limit {
			possible = false
		}

		if possible {
			fmt.Fprintln(out, V+1)
		} else {
			fmt.Fprintln(out, -1)
		}
	}
}