#[allow(unused_macros)]
macro_rules! input {
    ( $($t:ty),* ) => {{
        let mut s = String::new();
        std::io::stdin().read_line(&mut s);
        let mut splits = s.trim().split_whitespace();
        ($( { splits.next().unwrap().parse::<$t>().unwrap() },)*)
    }}
}

#[allow(unused_must_use)]
#[allow(unused_variables)]
fn solve() {
    let (q, ) = input!(usize);

    for _ in 0..q {
        let (n, k) = input!(u64, u64);
        if k == 1 {
            println!("{}", n - 1);
            continue;
        }

        let mut max = k;
        let mut count = 1;
        while n > max {
            max *= k;
            count += 1;
        }
        println!("{}", count);
    }
}

fn main() {
    solve();
}