#include <bits/stdc++.h>
using namespace std;
const int OO = (int)2e9;
const double PI = 2 * acos(0);
const double EPS = 1e-9;
map<string, int> m;
map<int, string> mm;
int a[10];
int mat[10][10];
int main() {
  m["S"] = 0;
  m["M"] = 1;
  m["L"] = 2;
  m["XL"] = 3;
  m["XXL"] = 4;
  mm[0] = "S";
  mm[1] = "M";
  mm[2] = "L";
  mm[3] = "XL";
  mm[4] = "XXL";
  cin >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
  for (int i = 0; i < (int)5; i++) mat[i][0] = i;
  mat[0][1] = 1;
  mat[0][2] = 2;
  mat[0][3] = 3;
  mat[0][4] = 4;
  mat[1][1] = 2;
  mat[1][2] = 0;
  mat[1][3] = 3;
  mat[1][4] = 4;
  mat[2][1] = 3;
  mat[2][2] = 1;
  mat[2][3] = 4;
  mat[2][4] = 0;
  mat[3][1] = 4;
  mat[3][2] = 2;
  mat[3][3] = 1;
  mat[3][4] = 0;
  mat[4][1] = 3;
  mat[4][2] = 2;
  mat[4][3] = 1;
  mat[4][4] = 0;
  int k;
  cin >> k;
  for (int i = 0; i < (int)k; i++) {
    string x;
    cin >> x;
    int id = m[x];
    for (int i = 0; i < 5; i++) {
      if (a[mat[id][i]]) {
        a[mat[id][i]]--;
        cout << mm[mat[id][i]] << endl;
        break;
      }
    }
  }
  return 0;
}
