#include #include #include #include #include #include using namespace std; char str[12]; //0 1 2 3 4 5 6 7 8 9 10 int days[13] = {0,31,28,31,30,31,30,31,31,30,31,30,31}; bool isrun(int num) { if((num%4 == 0&&num%100!=0)||num%400==0) return true; return false; } bool check() { int i; if(str[6]==str[7]&&str[7]==str[8]&&str[8]==str[9]&&str[9]==str[10]) return true; for(i = 6; i < 10; i++) { if(str[i]-str[i + 1] !=1) break; } if(i == 10) return true; for(i = 6; i < 10; i++) { if(str[i+1]-str[i] !=1) break; } if(i == 10) return true; int year = (str[3]-'0')*1000+(str[4]-'0')*100+(str[5]-'0')*10+(str[6]-'0'); bool flag = isrun(year); int month = (str[7]-'0')*10+(str[8]-'0'); int day = (str[9]-'0')*10+(str[10]-'0'); if(year<1980||year>2016) return false; if(month < 1||month > 12||day < 1 || day > 31) return false; if(flag == true) { if(month == 2 && day <= days[2] + 1) return true; else if(month != 2 && day <= days[month]) return true; else return false; } else { if(day <= days[month]) return true; else return false; } return false; } int main() { int re; scanf("%d",&re); while(re--) { int n; long long a,b; scanf("%d%I64d%I64d",&n,&a,&b); long long sum = 0; for(int i = 0; i < n; i++) { getchar(); scanf("%s",str); // cout << check() << endl; if(check()) sum+=a; else sum+=b; } printf("%I64d\n",sum); } }