2018 青岛ICPC区域赛M
#include<bits/stdc++.h>
using namespace std;
int TAB[10] = { 1,0,0,0,1,0,1,0,2,1};
int get_val(int x)
{
if(!x) return 1;
int ret = 0;
while(x) ret += TAB[x%10], x/=10;
return ret;
}
int main(void)
{
int T;
scanf("%d",&T);
while(T--)
{
int x,k;
scanf("%d%d",&x,&k);
while(k-- && x) x = get_val(x);
x? printf("%d\n",x) :puts(k&1? "0":"1");
}
}