int t; cin >> t; for (int cas = 1; cas <= t; cas ++) { cin >> n >> d >> c >> m; string s; cin >> s; bool flag = true; for (int i = 0; i < s.size(); i ++) { if (s[i] == 'D') if(d) { c += m; d--; } else { flag = false; break; } else if (c) c--; else { for (int j = i; j < s.size(); j ++) if (s[j] == 'D') { flag = false; } break; } }
if (flag) cout << "Case #" << cas << ": " << "YES" << endl; else cout << "Case #" << cas << ": " << "NO" << endl;