#include <bits/stdc++.h>
using namespace std;
int main() {
  string str[] = {"S", "M", "L", "XL", "XXL"};
  int a[10];
  for (int i = 0; i < 5; i++) {
    cin >> a[i];
  }
  int k;
  cin >> k;
  string s;
  for (int i = 0; i < k; i++) {
    cin >> s;
    int r = 0;
    for (r = 0; r < 5; r++)
      if (str[r] == s) break;
    for (int j = 0; j < 5; j++) {
      if (r + j < 5 && a[r + j] > 0) {
        a[r + j]--;
        cout << str[r + j] << endl;
        break;
      }
      if (r - j >= 0 && a[r - j] > 0) {
        a[r - j]--;
        cout << str[r - j] << endl;
        break;
      }
    }
  }
  return 0;
}
