#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[]={1,0,0,0,1,0,1,0,2,1};
ll f(ll x) {
ll sum = 0;
while (x) {
sum += a[x % 10];
x /= 10;
}
return sum;
}
ll g(ll x,ll k) {
ll g0 = x, g1;
for (ll i = 1; i <= k; i++) {
if (g0 == 0) {
if ((k - i) & 1) {
return 0;
} else {
return 1;
}
}
g1 = f(g0);
g0 = g1;
}
return g0;
}
int main() {
int T;
ll x, k;
scanf("%d", &T);
while (T--) {
scanf("%lld%lld", &x, &k);
printf("%lld
", g(x, k));
}
}
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
const int inf=0x3f3f3f3f;
ll n,m,a[maxn],k,mi,sum,i;
int main() {
int T;
scanf("%d", &T);
while (T--) {
mi = inf;
k = 0;
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
if (!a[i]) {
k++;
}
mi = min(mi, a[i]);
}
if (k > m) {
printf("Impossible
");
continue;
}
if (n == m) {
printf("Richman
");
continue;
}
if (m == 0) {
printf("%lld
", mi - 1);
continue;
}
sum = 0;
for (i = 1; i <= n; i++) {
if (k == m) {
break;
}
if (a[i]) {
sum += a[i];
k++;
}
}
mi = inf;
for (; i <= n; i++) {
if (a[i] != 0) {
mi = min(mi, a[i]);
}
}
printf("%lld
", mi + sum - 1);
}
return 0;
}