#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
string p, s;
int ne[N];
bool check(char a, char b)
{
if (a >= '0' && a <= '9' && b >= '0' && b <= '9') return true;
if (((a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z')) &&
((b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z'))) return true;
return false;
}
int getLen(string a, int pos)
{
stack<char> stk;
for (int i = pos; a[i]; i ++ )
{
if (a[i] == '(') stk.push(a[pos]);
if (a[i] == ')')
{
stk.pop();
if (stk.empty()) return i - pos;
}
}
return -1;
}
int main()
{
cin >> p;
cin >> s;
for (int i = 0; i < p.size(); i ++ )
if (p[i] >= '0' && p[i] <= '9')
{
string t = "";
for (int j = 0; j < p[i] - '0'; j ++ )
t = t + p.substr(i + 2, getLen(p, i + 1) - 1);
string _p = p.substr(0, i);
string p_ = p.substr(i + getLen(p, i + 1) + 2);
p =_p + t + p_;
}
for (int i = 0; i < p.size(); i ++ ) if (p[i] == 'N') p[i] = '0';
// cout << p << endl;
int n = p.size(), m = s.size();
for (int j = 0, i = 1 ; i < n; i ++ )
{
while (j && !check(p[i], p[j])) j = ne[j - 1];
if (check(p[i], p[j])) ne[i] = ++ j;
}
for (int j = 0, i = 0; i < m; i ++ )
{
while (j && !check(s[i], p[j])) j = ne[j - 1];
if (check(s[i], p[j])) j ++ ;
if (j == n)
{
j = ne[j - 1];
cout << s.substr(i - n + 1, p.size());
return 0;
}
}
cout << "!";
return 0;
}