#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[5];
  for (int i = 0; i < 5; i++) cin >> a[i];
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string maik;
    cin >> maik;
    int start;
    if (maik == "S")
      start = 0;
    else if (maik == "M")
      start = 1;
    else if (maik == "L")
      start = 2;
    else if (maik == "XL")
      start = 3;
    else
      start = 4;
    bool read = 0;
    int j = start, k = 0;
    while (1) {
      if (a[j + k] > 0 && j + k < 5) {
        read = 1;
        a[j + k]--;
        j += k;
        break;
      } else if (a[j - k] > 0 && j - k >= 0) {
        read = 1;
        a[j - k]--;
        j -= k;
        break;
      }
      k++;
    }
    if (j == 0)
      cout << "S" << endl;
    else if (j == 1)
      cout << "M" << endl;
    else if (j == 2)
      cout << "L" << endl;
    else if (j == 3)
      cout << "XL" << endl;
    else if (j == 4)
      cout << "XXL" << endl;
  }
}
