#include <bits/stdc++.h>
int main() {
  std::ios_base::sync_with_stdio(false);
  size_t Sn[5];
  for (auto& s : Sn) std::cin >> s;
  size_t k;
  std::cin >> k;
  std::string s;
  std::string Ss[5] = {"S", "M", "L", "XL", "XXL"};
  for (size_t i = 0; i < k; ++i) {
    std::cin >> s;
    size_t j = std::distance(Ss, std::find(Ss, Ss + 5, s));
    size_t g = j, l = j;
    for (; g < 4 && Sn[g] == 0; ++g)
      ;
    for (; l > 0 && Sn[l] == 0; --l)
      ;
    if (Sn[g] > 0 && (Sn[l] == 0 || g - j <= j - l))
      j = g;
    else
      j = l;
    Sn[j] -= 1;
    std::cout << Ss[j] << '\n';
  }
}
