#include <bits/stdc++.h>
using namespace std;
int kol[5][5] = {{0, 1, 2, 3, 4},
                 {1, 2, 0, 3, 4},
                 {2, 3, 1, 4, 0},
                 {3, 4, 2, 1, 0},
                 {4, 3, 2, 1, 0}};
int Na_licz(string r) {
  if (r == "S") return 0;
  if (r == "M") return 1;
  if (r == "L") return 2;
  if (r == "XL") return 3;
  if (r == "XXL") return 4;
}
string Na_str(int r) {
  if (r == 0) return "S";
  if (r == 1) return "M";
  if (r == 2) return "L";
  if (r == 3) return "XL";
  if (r == 4) return "XXL";
}
int main() {
  ios_base::sync_with_stdio(0);
  int il[5];
  for (int i = 0; i < 5; ++i) cin >> il[i];
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string roz;
    cin >> roz;
    int j = 0;
    while (il[kol[Na_licz(roz)][j]] == 0) ++j;
    cout << Na_str(kol[Na_licz(roz)][j]) << endl;
    --il[kol[Na_licz(roz)][j]];
  }
  return 0;
}
