#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  std::map<string, int> sizeIndex = {
      {"S", 0}, {"M", 1}, {"L", 2}, {"XL", 3}, {"XXL", 4}};
  std::array<int, 5> stock;
  for (int i = 0; i < 5; i++) {
    cin >> stock[i];
  }
  auto getFromIindex = [sizeIndex](const int index) {
    for (const auto& a : sizeIndex) {
      if (a.second == index) {
        return a.first;
      }
    }
    return std::string{};
  };
  auto checkAt = [stock, getFromIindex](int index) mutable {
    if (index < 0 || index > 4) return false;
    if (stock[index] > 0) {
      --stock[index];
      cout << getFromIindex(index) << endl;
      return true;
    }
    return false;
  };
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string str;
    cin >> str;
    const int index = sizeIndex[str];
    if (checkAt(index)) {
      continue;
    }
    int ii = 0;
    while (true) {
      ii++;
      if (checkAt(index + ii) || checkAt(index - ii)) {
        break;
      }
    }
  }
  return 0;
}
