#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  vector<int> a;
  vector<string> size = {"S", "M", "L", "XL", "XXL"};
  int i;
  int n = 5;
  for (i = 0; i < 5; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  int q;
  cin >> q;
  while (q--) {
    int k = 0;
    string inp;
    cin >> inp;
    if (inp == "S") k = 0;
    if (inp == "M") k = 1;
    if (inp == "L") k = 2;
    if (inp == "XL") k = 3;
    if (inp == "XXL") k = 4;
    int shirt = 0;
    int p = 0;
    while (shirt == 0) {
      if (k + p < n && a[k + p] != 0) {
        shirt = 1;
        a[k + p]--;
        cout << size[k + p] << endl;
        break;
      } else if (k - p >= 0 && a[k - p] != 0) {
        shirt = 1;
        a[k - p]--;
        cout << size[k - p] << endl;
        break;
      }
      p++;
    }
  }
}
