#include <bits/stdc++.h>
using namespace std;
string x;
int a[5], n;
string g[5] = {"S", "M", "L", "XL", "XXL"};
int main() {
  for (int i = 0; i < 5; ++i) cin >> a[i];
  cin >> n;
  while (n--) {
    cin >> x;
    int idx = -1;
    for (int i = 0; idx == -1; ++i)
      if (x == g[i]) idx = i;
    if (a[idx]) {
      --a[idx];
      cout << g[idx] << endl;
      continue;
    }
    int p1 = idx + 1, p2 = idx - 1;
    while (1) {
      if (p1 < 5 && a[p1]) {
        --a[p1];
        cout << g[p1] << endl;
        break;
      }
      ++p1;
      if (p2 > -1 && a[p2]) {
        --a[p2];
        cout << g[p2] << endl;
        break;
      }
      --p2;
    }
  }
}
