#include <bits/stdc++.h>
using namespace std;
int a[5];
string s[] = {"S", "M", "L", "XL", "XXL"};
map<string, int> mp;
int main() {
  ios_base::sync_with_stdio(0);
  mp["S"] = 0;
  mp["M"] = 1;
  mp["L"] = 2;
  mp["XL"] = 3;
  mp["XXL"] = 4;
  int n;
  for (int i = 0; i < 5; ++i) cin >> a[i];
  cin >> n;
  while (n--) {
    string sz;
    cin >> sz;
    int i = mp[sz];
    if (a[i] > 0) {
      cout << s[i] << endl;
      a[i]--;
    } else {
      int mn = 6, j = 0, k = -1;
      for (; j < 5; ++j) {
        if (a[j] && i != j && abs(i - j) <= mn) {
          k = j;
          mn = abs(i - j);
        }
      }
      cout << s[k] << endl;
      a[k]--;
    }
  }
}
