#include
#include
#include
#include
#include
int main() {
std::ios::sync_with_stdio(false);
std::map reagents_by_color;
std::cin >> reagents_by_color["Blue"] >> reagents_by_color["Red"] >> reagents_by_color["Yellow"];
int num_reagents;
std::cin >> num_reagents;
std::set required_colors;
std::string current_color;
for (int _ = 0; _ < num_reagents; _++) {
std::cin >> current_color;
required_colors.insert(current_color);
}
int total_combinations = 1;
for (const auto& color: required_colors) {
total_combinations *= reagents_by_color[color];
}
std::cout