#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
map<string, int> m;
int main() {
  long long n, v[5], i, fl, ind, k;
  string x, stx[5] = {"S", "M", "L", "XL", "XXL"};
  for (i = 0; i < 5; i++) cin >> v[i];
  cin >> n;
  while (n--) {
    k = 0;
    cin >> x;
    if (x == "S")
      ind = 0;
    else if (x == "M")
      ind = 1;
    else if (x == "L")
      ind = 2;
    else if (x == "XL")
      ind = 3;
    else if (x == "XXL")
      ind = 4;
    while (1) {
      if (v[(ind + k) > 4 ? 4 : (ind + k)] > 0) {
        ind += k;
        break;
      } else if (v[(ind - k) < 0 ? 0 : ind - k] > 0) {
        ind -= k;
        break;
      } else
        k++;
    }
    cout << stx[ind] << endl;
    v[ind]--;
  }
}
