1 /*
2 * this code is made by xcw0754
3 * Problem: 1704
4 * Verdict: Accepted
5 * Submission Date: 2015-07-16 10:18:37
6 * Time: 4MS
7 * Memory: 36836KB
8 */
9 //#pragma comment(linker,"/STACK:102400000,102400000")
10 #include <iostream>
11 #include <stdio.h>
12 #include <string.h>
13 #include <vector>
14 #include <stack>
15 #include <algorithm>
16 #include <map>
17 #include <bits/stdc++.h>
18 #define LL long long
19 #define pii pair<int,int>
20 #define INF 0x7f7f7f7f
21 using namespace std;
22 const int N=500005;
23 int up;
24 int s[N][18];
25
26
27 void pre_cal()
28 {
29 up=0;
30 for(int i=100; i<1000; i++)
31 {
32 for(int j=10; j<100; j++)
33 {
34 s[up][0]=i/100; //不能为0
35 s[up][1]=i/10%10;
36 s[up][2]=i%10;
37
38 s[up][3]=j/10; //不能为0
39 s[up][4]=j%10;
40
41 int tmp=i*(j%10); //第3行
42 s[up][5]=tmp/1000; //不能为0
43 if(!s[up][5] || s[up][5]>9) continue;
44 s[up][6]=tmp/100%10;
45 s[up][7]=tmp/10%10;
46 s[up][8]=tmp%10;
47
48 tmp=i*(j/10); //第4行
49 s[up][9]=tmp/100; //不能为0
50 if(!s[up][9]|| s[up][9]>9) continue;
51 s[up][10]=tmp/10%10;
52 s[up][11]=tmp%10;
53
54 tmp=i*j; //第5行
55 s[up][12]=tmp/10000;//不能为0
56 if(!s[up][12]) continue;
57 s[up][13]=tmp/1000%10;
58 s[up][14]=tmp/100%10;
59 s[up][15]=tmp/10%10;
60 s[up][16]=tmp%10;
61 up++;
62 }
63 }
64
65 }
66
67 int now[18];
68 vector<int> alk;
69 char c[18];
70
71 void get_input()
72 {
73 memset(now,0,sizeof(now));
74 alk.clear();
75
76 scanf("%s",c);
77 scanf("%s",c+3);
78 scanf("%s",c+5);
79 scanf("%s",c+9);
80 scanf("%s",c+12);
81
82 for(int i=0; i<17; i++)
83 if(isdigit(c[i]))
84 {
85 now[i]=c[i]-‘0‘;
86 alk.push_back(i);
87 }
88 }
89
90
91 int cal()
92 {
93 int ans=0;
94 for(int i=0; i<up; i++)
95 {
96 int j;
97 for(j=0; j<alk.size(); j++) //这几个都要匹配
98 {
99 int k=alk[j];
100 if(now[k]!=s[i][k]) break;
101 }
102 if(j==alk.size())
103 ans++;
104 }
105 return ans;
106 }
107
108 int main()
109 {
110 //freopen("input.txt", "r", stdin);
111 pre_cal();
112 int t;
113 scanf("%d",&t);
114 while(t--)
115 {
116 get_input();
117 printf("%d\n",cal());
118 }
119 return 0;
120 }