点击打开链接
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string.h>
#include<cstring>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include <string>
#include <map>
#define LL long long
#define inf 0x3f3f3f3f
#define maxn 1e5+5
using namespace std;
int a, b, d, n, T;
void solve()
{
LL ans = 0;
if(n >= 3){
int c = (a * 100 + a * 10 + a) * b;
if(d == c / 1000 && d != 0) ans++;///处理最高位的。
if(d == c % 1000 / 100) ans += n - 2;///处理中间的
if(d == c % 100 / 10) ans ++;///处理倒数第二位
if(d == c % 10) ans ++;///处理最后一位。
}
else{
int A = 0;
for(int i=0;i<n;i++) A = A * 10 + a;
A *= b;
while(A){
if( A % 10 == d) ans++;
A /= 10;
}
}
printf("%lld\n", ans);
}
int main()
{
scanf("%d", &T);
while(T --){
scanf("%d%d%d%d", &a, &b, &d, &n);
solve();
}
return 0;
}