#include #include #include using namespace std; char num[100005][12]; int t, a, b, n; int dayy[2][12] = { { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; bool check1(char k[]) { int a0 = k[6] - k[7]; int a1 = k[7] - k[8]; int a2 = k[8] - k[9]; int a3 = k[9] - k[10]; if (a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0) return true; return false; } bool check2(char k[]) { int a0 = k[6] - k[7]; int a1 = k[7] - k[8]; int a2 = k[8] - k[9]; int a3 = k[9] - k[10]; if (a1 == 1 && a2 == 1 && a3 == 1 && a0 == 1) return true; else if (a1 == -1 && a2 == -1 && a3 == -1 && a0 == -1) return true; return false; } bool check3(char k[]) { int year = (k[3] - '0') * 1000 + (k[4] - '0') * 100 + (k[5] - '0') * 10 + (k[6] - '0'); int month = (k[7] - '0') * 10 + (k[8] - '0'); int day = (k[9] - '0') * 10 + (k[10] - '0'); if(year >= 1980 && year <= 2016) { if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { if (month <= 12 && month >= 1) { if (dayy[1][month - 1] >=day && day >= 1) return true; } } else { if (month <= 12 && month >= 1) { if (dayy[0][month - 1] >=day && day >= 1) return true; } } } return false; } int main(void) { while (scanf("%d", &t) != EOF) { while (t--) { __int64 sum = 0; bool flag = false; scanf("%d %d %d", &n, &a, &b); for (int i = 0; i < n; i++) { flag = false; getchar(); scanf("%s", num[i]); if (check1(num[i])) flag = true; if (check2(num[i])) flag = true; if (check3(num[i])) flag = true; if (flag) sum += a; else sum += b; } printf("%I64d\n", sum); } } return 0; }