#include <bits/stdc++.h>
using namespace std;
int main() {
  string s[5] = {"S", "M", "L", "XL", "XXL"};
  int a[5];
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string t;
    cin >> t;
    int id = 0;
    while (s[id] != t) id++;
    for (int d = 0; d < 5; d++) {
      int x = max(id - d, 0);
      int y = min(id + d, 4);
      if (a[y]) {
        a[y]--;
        cout << s[y] << "\n";
        break;
      } else if (a[x]) {
        a[x]--;
        cout << s[x] << "\n";
        break;
      }
    }
  }
  return 0;
}
