#include <bits/stdc++.h>
using namespace std;
int i, j, k, t[5], b[5][5] = {0, 1, 2, 3, 4, 1, 2, 0, 3, 4, 2, 3, 1,
                              4, 0, 3, 4, 2, 1, 0, 4, 3, 2, 1, 0};
string s, v[5] = {"S", "M", "L", "XL", "XXL"};
int main() {
  for (; i < 5;) cin >> t[i++];
  for (cin >> k; k--; t[b[i][j]]--, cout << v[b[i][j]] << endl) {
    for (cin >> s, i = j = 0; s != v[i];) i++;
    for (; !t[b[i][j]];) j++;
  }
}
