#include <bits/stdc++.h>
using namespace std;
int main() {
  string Ts[] = {"S", "M", "L", "XL", "XXL"};
  int n, a[5];
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int j;
    for (j = 0; s != Ts[j]; j++)
      ;
    int m = -9999;
    for (int c = 0; c < 5; c++) {
      if (!a[c]) {
        continue;
      }
      if (abs(c - j) <= abs(m - j)) {
        m = c;
      }
    }
    cout << Ts[m] << '\n';
    a[m]--;
  }
  return 0;
}
