#include using namespace std; const int MaxN = (int)1e5 + 10; const int INF = (int)1e9; const int MOD = (int)1e9 + 7; int bpow(int a, int n) { int res = 1; while (n > 0) { if (n & 1) { res = 1LL * res * a % MOD; } a = 1LL * a * a % MOD; n /= 2; } return res; } void solve() { long long n; int w; scanf("%lld%d", &n, &w); assert (n >= 2 && n <= 1e18); assert (-300 <= w && w <= 300); int mul = w >= 0 ? max(9 - w, 0) : max(0, 10 + w); cout << 1LL * mul * bpow(10, (n - 2) % (MOD - 1)) % MOD << '\n'; } int main() { // freopen("input.txt", "r", stdin); int t; scanf("%d", &t); assert (1 <= t && t <= 100000); while (t --> 0) { solve(); } return 0; }