#include #include #include #include #include #include #include #include #include #include #include #include #include #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef __int128_t ll; template vector> vec2d(int n, int m, T v){ return vector>(n, vector(m, v)); } template vector>> vec3d(int n, int m, int k, T v){ return vector>>(n, vector>(m, vector(k, v))); } template void print_vector(vector v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } __int128 parse(string &s) { __int128 ret = 0; for (int i = 0; i < s.length(); i++) if ('0' <= s[i] && s[i] <= '9') ret = 10 * ret + s[i] - '0'; return ret; } istream & operator >> (istream &in, __int128_t &m){ string s; cin >> s; m = parse(s); return in; } ostream &operator<<(std::ostream &dest, __int128_t value) { ostream::sentry s(dest); if (s) { __uint128_t tmp = value < 0 ? -value : value; char buffer[128]; char *d = end(buffer); do { --d; *d = "0123456789"[tmp % 10]; tmp /= 10; } while (tmp != 0); if (value < 0) { --d; *d = '-'; } int len = end(buffer) - d; if (dest.rdbuf()->sputn(d, len) != len) { dest.setstate(ios_base::badbit); } } return dest; } ll mod_pow(ll a, ll n, ll mod) { ll ans = 1; while (n > 0) { if (n&1) ans = (ans*a)%mod; a = (a*a)% mod; n >>= 1; } return ans; } void solve(){ ll a, b, c; cin >> a >> b >> c; while(b%2 == 0){ if(a%2 == 0){ a /= 2; }else{ a *= 5; c--; } b /= 2; } while(b%5 == 0){ if(a%5 == 0){ a /= 5; }else{ a *= 2; c--; } b /= 5; } // cout << a << ' ' << b << ' ' << c << endl; if(c <= 0){ ll x = a/b; while(c != 0) { x /= 10; c++; } cout << x%10 << endl; return; } ll x = (a*mod_pow(10, c, b))%b; int r = (10-x%10)%10; for(int i = 0; i < 10; i++){ if((b*i)%10 == r){ cout << i << endl; } } } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); }