#include <bits/stdc++.h>
using namespace std;
int ShirtToInt(string shirt) {
  if (shirt == "S") return 0;
  if (shirt == "M") return 1;
  if (shirt == "L") return 2;
  if (shirt == "XL") return 3;
  return 4;
}
string IntToShirt(int id) {
  switch (id) {
    case 0:
      return "S";
    case 1:
      return "M";
    case 2:
      return "L";
    case 3:
      return "XL";
    case 4:
      return "XXL";
  }
}
int main() {
  int nt = 5;
  vector<int> shirts;
  int kids;
  for (int(i) = 0; (i) < (nt); ++(i)) {
    int buf;
    cin >> buf;
    shirts.push_back(buf);
  }
  cin >> kids;
  for (int(i) = 0; (i) < (kids); ++(i)) {
    pair<int, int> best = make_pair(1023123123, 0);
    string wantshirt;
    cin >> wantshirt;
    int id = ShirtToInt(wantshirt);
    for (int(j) = 0; (j) < (5); ++(j))
      if (shirts[j]) {
        best = min((best), (make_pair(abs(j - id), -j)));
      }
    shirts[best.second * -1] -= 1;
    cout << IntToShirt(best.second * -1) << endl;
  }
  return 0;
}
