#include <bits/stdc++.h>
using namespace std;
int main() {
  cout << fixed;
  cout.precision(9);
  int a[5];
  for (int i = 0; i < 5; ++i) {
    cin >> a[i];
  }
  string sz[5] = {"S", "M", "L", "XL", "XXL"};
  int k;
  cin >> k;
  while (k--) {
    string s;
    cin >> s;
    int i = 0;
    while (sz[i] != s) {
      ++i;
    }
    int j = -1;
    for (int t = 4; t >= 0; --t) {
      if (a[t] > 0 && (j < 0 || abs(j - i) > abs(t - i))) {
        j = t;
      }
    }
    a[j]--;
    cout << sz[j] << endl;
  }
  return 0;
}
