#include <bits/stdc++.h>
using namespace std;
int main() {
  int arr[5];
  for (int i = 0; i < 5; i++) {
    cin >> arr[i];
  }
  int n;
  cin >> n;
  string arr1[5] = {"S", "M", "L", "XL", "XXL"};
  int arr2[5][5] = {{0, 1, 2, 3, 4},
                    {1, 2, 0, 3, 4},
                    {2, 3, 1, 4, 0},
                    {3, 4, 2, 1, 0},
                    {4, 3, 2, 1, 0}};
  for (int i = 0; i < n; i++) {
    string a;
    cin >> a;
    int j;
    for (int t = 0; t < 5; t++) {
      if (arr1[t] == a) {
        j = t;
        break;
      }
    }
    for (int t = 0; t < 5; t++) {
      if (arr[arr2[j][t]] > 0) {
        arr[arr2[j][t]]--;
        cout << arr1[arr2[j][t]] << endl;
        break;
      }
    }
  }
}
