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