#include #include using namespace std; int yue1[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; bool pd(int year,int yue ,int ri) { //cout<=1980&&year<=2016&&yue>=1&&yue<=12) { if(ri>0&&ri<=yue1[yue])return true; return false; } return false; } int main() { int t; cin>>t; while(t--) { int a,b,n; cin>>n>>a>>b; long long int ans=0; while(n--) { char s[13]; scanf("%s",s); int nian=(s[3]-'0')*1000+(s[4]-'0')*100+(s[5]-'0')*10+(s[6]-'0'); int yue=(s[7]-'0')*10+(s[8]-'0'); int ri=(s[9]-'0')*10+(s[10]-'0'); if(s[10]==s[9]&&s[9]==s[8]&&s[8]==s[7]&&s[7]==s[6])ans+=a; else if(s[10]-s[9]==1&&s[9]-s[8]==1&&s[8]-s[7]==1&&s[7]-s[6]==1)ans+=a; else if(s[10]-s[9]==-1&&s[9]-s[8]==-1&&s[8]-s[7]==-1&&s[7]-s[6]==-1)ans+=a; else if(pd(nian,yue,ri))ans+=a; else ans+=b; } cout<