#include <bits/stdc++.h>
using namespace std;
string s, sz[5] = {"S", "M", "L", "XL", "XXL"};
int num, lf[5];
int main() {
  for (int i = 0; i < 5; i++) cin >> lf[i];
  cin >> num;
  for (int i = 1; i <= num; i++) {
    cin >> s;
    int j;
    for (j = 0; s != sz[j]; j++)
      ;
    int zh = -1000;
    for (int k = 0; k < 5; k++) {
      if (lf[k] == 0)
        continue;
      else if (abs(k - j) <= abs(zh - j)) {
        zh = k;
      }
    }
    cout << sz[zh] << endl;
    lf[zh]--;
  }
  return 0;
}
