#include <bits/stdc++.h>
using namespace std;
string arr[5] = {"S", "M", "L", "XL", "XXL"};
int f(string str) {
  for (int i = 0; i < 5; ++i)
    if (str == arr[i]) return i;
  return -1;
}
int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  int c[5], k;
  for (int i = 0; i < 5; ++i) cin >> c[i];
  cin >> k;
  for (int i = 0; i < k; ++i) {
    string str;
    cin >> str;
    int code = f(str);
    int mn = 6, safe = -1;
    for (int i = 0; i < 5; ++i)
      if (c[i] > 0 && mn >= abs(code - i)) mn = abs(code - i), safe = i;
    c[safe]--;
    cout << arr[safe] << endl;
  }
  return 0;
}
