#include <bits/stdc++.h>
using namespace std;
int to_type(string s) {
  if (s == "S") return 0;
  if (s == "M") return 1;
  if (s == "L") return 2;
  if (s == "XL") return 3;
  if (s == "XXL") return 4;
}
const string to_shirt[] = {"S", "M", "L", "XL", "XXL"};
int main() {
  int c[5];
  for (int i = 0; i < 5; ++i) {
    cin >> c[i];
  }
  int k;
  cin >> k;
  while (k--) {
    string s;
    cin >> s;
    int t = to_type(s);
    int g = -1;
    if (c[t] > 0) {
      --c[t];
      g = t;
    } else {
      for (int i = 4; i >= 0; --i) {
        if (c[i] > 0) {
          if (g == -1 || fabs(i - t) < fabs(g - t)) {
            g = i;
          }
        }
      }
      --c[g];
    }
    cout << to_shirt[g] << endl;
  }
  return 0;
}
