
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>

auto& in = std::cin;
auto& out = std::cout;

int32_t N;
std::string S[10000];
std::string T;

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> S[i];
	}
	in >> T;

	int32_t pre_count = 0;
	int32_t aft_count = 0;
	for (int32_t i = 0; i < N; ++i)
	{
		int res = 0;//res<0でSが前
		int32_t j = 0, length = std::min(S[i].size(), T.size());
		for (; j < length; ++j)
		{
			if (S[i][j] == '?') {
				break;
			}
			if (S[i][j] < T[j]) {
				res = -1;
				break;
			}
			if (T[j] < S[i][j]) {
				res = +1;
				break;
			}
		}
		if (res < 0) {
			++pre_count;
		}
		else if (res > 0) {
			++aft_count;
		}
		else
		{
			const auto old_j= j;
			//前があり得るか
			bool enable= S[i].size() <= T.size();
			for (; j < length; ++j)
			{
				if (S[i][j] == '?') {
					if (T[j] > 'a') {
						enable = true;
						break;
					}
					else {
						continue;
					}
				}
				if (S[i][j] < T[j]) {
					enable = true;
					break;
				}
				if (T[j] < S[i][j]) {
					enable = false;
					break;
				}
			}
			if (!enable) {
				++aft_count;
			}
			//後ろがあり得るか
			enable = S[i].size() >= T.size();
			for (j=old_j; j < length; ++j)
			{
				if (S[i][j] == '?') {
					if (T[j] < 'z') {
						enable = true;
						break;
					}
					else {
						continue;
					}
				}
				if (S[i][j] < T[j]) {
					enable = false;
					break;
				}
				if (T[j] < S[i][j]) {
					enable = true;
					break;
				}
			}
			if (!enable) {
				++pre_count;
			}
		}
#if 0
		auto pre = S[i].find_first_of('?');
		if (pre == std::string::npos) { pre = S[i].size(); }
		int res = 0;
		for (int32_t j = 0, length=std::min(pre,T.size()); j < length; ++j)
		{
			if (S[i][j] < T[j]) {
				res = -1;
				break;
			}
			if (T[j] < S[i][j]) {
				res = +1;
				break;
			}
		}
		if (res < 0) {
			++pre_count;
		}
		else if (res > 0) {
			++aft_count;
		}
		else
		{
			if (T.size() < pre) {
				++aft_count;
			}
			if (T.size() == pre) {
				if (T.size() < S[i].size()) {
					++aft_count;
				}
			}
		}
#endif
	}
	bool f = true;
	for (int32_t i = pre_count+1; i <= N+1- aft_count; ++i)
	{
		if (!f) { out << ' '; }
		out << i;
		f = false;
	}
	out << endl;

	return 0;
}
#endif
