#include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int answer;
bool check[10];
vector<string> g_user_id;
vector<string> g_banned_id;
vector<string> candi;
set<vector<string>> s;
void permutation() {
if (candi.size()==g_banned_id.size()) {
vector<string> sortedCandi = candi;
sort(sortedCandi.begin(), sortedCandi.end());
if (s.count(sortedCandi)) return;
for (int i = 0; i < g_banned_id.size(); i++) {
if (candi[i].size() != g_banned_id[i].size()) return;
for (int j = 0; j < candi[i].size(); j++) {
if (g_banned_id[i][j] == '*') continue;
if (candi[i][j] != g_banned_id[i][j]) return;
}
}
s.insert(sortedCandi);
answer++;
return;
}
for (int i = 0; i < g_user_id.size(); i++) {
if (!check[i]) {
check[i] = true;
candi.push_back(g_user_id[i]);
permutation();
candi.pop_back();
check[i] = false;
}
}
}
int solution(vector<string> user_id, vector<string> banned_id) {
g_user_id = user_id;
g_banned_id = banned_id;
permutation();
return answer;
}