#include<bits/stdc++.h>
using namespace std;
int main()
{
string a,x;
getline(cin,a);a+=" ed";
int id=100,yes=1,no=100;
stringstream b(a);
vector<string> d;
while ( b>>x ) {
if ( x=="or"||x=="ed" ) {
if ( x=="or" ) no+=2;
else no=0;
int len = d.size();
for ( int i=0; i<len-3; i+=3 ) {
printf("%d(j%s,%s,%s,%d)\n",id,d[i+1].c_str(),d[i].c_str(),d[i+2].c_str(),id+2);
id++;
printf("%d(j,_,_,%d)\n",id,no);
no=id++;
}
printf("%d(j%s,%s,%s,%d)\n",id,d[len-2].c_str(),d[len-3].c_str(),d[len-1].c_str(),yes);
yes = id++;
printf("%d(j,_,_,%d)\n",id,no);
id ++;
d.clear();
if ( x=="ed" ) break;
}
else if ( x=="and" ) no+=2;
else d.push_back(x);
}
return 0;
}