#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s, ss[5] = {"S", "M", "L", "XL", "XXL"};
  int* l = new int[5];
  for (int i = 0; i < 5; ++i) cin >> l[i];
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s;
    int a;
    for (int i = 0; i < 5; ++i)
      if (ss[i] == s) {
        a = i;
        break;
      }
    if (l[a]) {
      --l[a];
      cout << ss[a] << endl;
    } else {
      bool f = 1;
      for (int j = 1; f; ++j) {
        int x = a + ((j + 1) >> 1) * (2 * (j % 2) - 1);
        if (x >= 0 && x < 5 && f && l[x]) {
          --l[x];
          cout << ss[x] << endl;
          f = 0;
        }
      }
    }
  }
  return 0;
}
