#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-8;
void fast() {
  std::ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool sortby(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first >= b.first && a.second >= b.second) return true;
  return false;
}
double area(int x1, int y1, int x2, int y2, int x3, int y3) {
  return abs((x1 * (y2 - y3) + x2 * (y3 - y1) + x3 * (y1 - y2)) / 2.0);
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int arr[5][1005], arr2[5][1005], arr3[5];
int main() {
  fast();
  for (int i = 0; i < 5; i++) cin >> arr3[i];
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    string s;
    cin >> s;
    if (s == "S")
      arr[0][i] = 1;
    else if (s == "M")
      arr[1][i] = 1;
    else if (s == "L")
      arr[2][i] = 1;
    else if (s == "XL")
      arr[3][i] = 1;
    else
      arr[4][i] = 1;
  }
  for (int j = 0; j < k; j++) {
    for (int i = 0; i < 5; i++) {
      if (arr[i][j]) {
        if (arr3[i]) {
          arr3[i]--;
          arr2[i][j] = i;
        } else {
          bool b = false;
          bool c = true;
          int g = i + 1, h = i - 1;
          while (!b) {
            for (g; g < 5 && !b; g++) {
              if (arr3[g]) {
                arr3[g]--;
                arr2[i][j] = g;
                b = true;
                break;
              } else {
                g++;
                break;
              }
            }
            for (h; h >= 0 && !b; h--) {
              if (arr3[h]) {
                arr3[h]--;
                arr2[i][j] = h;
                b = true;
                break;
              } else {
                h--;
                break;
              }
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < k; i++) {
    if (arr[0][i]) {
      if (arr2[0][i] == 0) {
        cout << "S" << endl;
      } else if (arr2[0][i] == 1)
        cout << "M" << endl;
      else if (arr2[0][i] == 2)
        cout << "L" << endl;
      else if (arr2[0][i] == 3)
        cout << "XL" << endl;
      else if (arr2[0][i] == 4)
        cout << "XXL" << endl;
    } else if (arr[1][i]) {
      if (arr2[1][i] == 0) {
        cout << "S" << endl;
      } else if (arr2[1][i] == 1)
        cout << "M" << endl;
      else if (arr2[1][i] == 2)
        cout << "L" << endl;
      else if (arr2[1][i] == 3)
        cout << "XL" << endl;
      else if (arr2[1][i] == 4)
        cout << "XXL" << endl;
    } else if (arr[2][i]) {
      if (arr2[2][i] == 0) {
        cout << "S" << endl;
      } else if (arr2[2][i] == 1)
        cout << "M" << endl;
      else if (arr2[2][i] == 2)
        cout << "L" << endl;
      else if (arr2[2][i] == 3)
        cout << "XL" << endl;
      else if (arr2[2][i] == 4)
        cout << "XXL" << endl;
    } else if (arr[3][i]) {
      if (arr2[3][i] == 0) {
        cout << "S" << endl;
      } else if (arr2[3][i] == 1)
        cout << "M" << endl;
      else if (arr2[3][i] == 2)
        cout << "L" << endl;
      else if (arr2[3][i] == 3)
        cout << "XL" << endl;
      else if (arr2[3][i] == 4)
        cout << "XXL" << endl;
    } else if (arr[4][i]) {
      if (arr2[4][i] == 0) {
        cout << "S" << endl;
      } else if (arr2[4][i] == 1)
        cout << "M" << endl;
      else if (arr2[4][i] == 2)
        cout << "L" << endl;
      else if (arr2[4][i] == 3)
        cout << "XL" << endl;
      else if (arr2[4][i] == 4)
        cout << "XXL" << endl;
    }
  }
  return 0;
}
