#include <algorithm> using namespace std; int main() { int t = 0; scanf("%d",&t); while(t--) { int a,b,d,n; scanf("%d%d%d%d", &a, &b, &d, &n); if(n < 5){ int now = 1; n--; while(n--) { now = now * 10 + 1; } int sum = a*now * b; int ans = 0; while(sum) { if(sum % 10 == d) ans++; sum /= 10; } printf("%d\n",ans); } else{ int num = a*11111*b; int now = a * b; int len; if(now >= 10) len = 1; else len = 0; //printf("%d\n",num); int s,l,r,e; e = num % 10; num /= 10; r = num %10; num /= 10; l = num % 10; num /= 10; while(num > 10) num /= 10; s = num; int sum = 0; if(d == s) sum++; if(d == r) sum++; if(d == l) sum += n-3+len; if(d == e) sum++; printf("%d\n",sum); } } return 0; }