#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, i, a[5], j;
  for (long long int i = 0; i < 5; i++) cin >> a[i];
  cin >> n;
  string x;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    long long int f = 0;
    if (x == "S") f = 0;
    if (x == "M") f = 1;
    if (x == "L") f = 2;
    if (x == "XL") f = 3;
    if (x == "XXL") f = 4;
    if (a[f] > 0) {
      if (f == 0)
        cout << "S";
      else if (f == 1)
        cout << "M";
      else if (f == 2)
        cout << "L";
      else if (f == 3)
        cout << "XL";
      else if (f == 4)
        cout << "XXL";
      a[f]--;
    } else {
      long long int g = -1, h = 0;
      if (f < 4) {
        if (a[f + 1] > 0) {
          if (f + 1 == 0)
            cout << "S";
          else if (f + 1 == 1)
            cout << "M";
          else if (f + 1 == 2)
            cout << "L";
          else if (f + 1 == 3)
            cout << "XL";
          else if (f + 1 == 4)
            cout << "XXL";
          a[f + 1]--;
          h = 1;
        } else if (f - 1 >= 0 && a[f - 1] > 0) {
          if (f - 1 == 0)
            cout << "S";
          else if (f - 1 == 1)
            cout << "M";
          else if (f - 1 == 2)
            cout << "L";
          else if (f - 1 == 3)
            cout << "XL";
          else if (f - 1 == 4)
            cout << "XXL";
          a[f - 1]--;
          h = 1;
        }
        if (h == 1) {
          cout << "\n";
          continue;
        }
      }
      for (j = f; j < 5; j++) {
        if (a[j] > 0) {
          g = j;
          break;
        }
      }
      if (g >= 0) {
        if (g == 0)
          cout << "S";
        else if (g == 1)
          cout << "M";
        else if (g == 2)
          cout << "L";
        else if (g == 3)
          cout << "XL";
        else if (g == 4)
          cout << "XXL";
        a[g]--;
      } else {
        for (j = f; j >= 0; j--) {
          if (a[j] > 0) {
            g = j;
            break;
          }
        }
        if (g == 0)
          cout << "S";
        else if (g == 1)
          cout << "M";
        else if (g == 2)
          cout << "L";
        else if (g == 3)
          cout << "XL";
        else if (g == 4)
          cout << "XXL";
        a[g]--;
      }
    }
    cout << "\n";
    cin.ignore();
  }
  return 0;
}
