#include <bits/stdc++.h>
using namespace std;
int N[10];
string shirt[5] = {"S", "M", "L", "XL", "XXL"};
map<string, int> mp;
int main() {
  int K, i, d;
  for ((i) = 0; (i) < (int)(5); (i)++) cin >> N[i];
  cin >> K;
  for ((i) = 0; (i) < (int)(5); (i)++) mp[shirt[i]] = i;
  for ((i) = 0; (i) < (int)(K); (i)++) {
    string s;
    cin >> s;
    int x = mp[s];
    int ans = -1;
    for (d = 0;; d++) {
      if (x + d >= 0 && x + d < 5 && N[x + d] > 0) {
        ans = x + d;
        break;
      }
      if (x - d >= 0 && x - d < 5 && N[x - d] > 0) {
        ans = x - d;
        break;
      }
    }
    N[ans]--;
    cout << shirt[ans] << endl;
  }
  return 0;
}
