#include <bits/stdc++.h> using namespace std; long long t , x , a , b; int main(){ cin >> t; while (t --){ cin >> x >> a; printf ("%lld " , x); for (;b != x;){ b = x; x = (x + a) / a; if(b != x) printf ("%lld " , x); } printf ("\n"); } return 0; }