#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
using namespace std;
#define X first
#define Y second
#define eps 1e-2
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;
const int N = 1e5+2;
const int INF = 1<<30;
const int mod = 1e9+7;
int n,m;
string s1[N],S[N];
map<string,int> to;
pair<string,string> mp2[N];
pair<int,int> mp3[N];
int OP[N],cur[N];
int cal(int pos,int now){
int res=0;
for(int i=1;i<=n;i++){
if(OP[i]==0) res+=S[i][pos]-'0',cur[mp3[i].first]=S[i][pos]-'0';
else{
string s2=mp2[i].first,s3=mp2[i].second;
int tp1=(s2[0]=='?'?now:cur[mp3[i].first]);
int tp2=(s3[0]=='?'?now:cur[mp3[i].second]);
if(OP[i]==1) res+=tp1|tp2,cur[i]=tp1|tp2;
else if(OP[i]==2) res+=tp1&tp2,cur[i]=tp1&tp2;
else res+=tp1^tp2,cur[i]=tp1^tp2;
}
}
return res;
}
void solve(){
cin>>n>>m;
to["?"]=-1;
for(int i=1;i<=n;i++){
string s;
cin>>s;s1[i]=s;to[s]=i;
cin>>s;
cin>>s;
if(isdigit(s[0])) S[i]=s,OP[i]=0,mp3[i]={i,0};
else{
string s2,s3;cin>>s2>>s3;
OP[i]=(s2[0]=='O'?1:(s2[0]=='A'?2:3));
mp2[i]={s,s3};
mp3[i]={to[s],to[s3]};
}
}
string ans1="",ans2="";
for(int i=0;i<m;i++){
int tp1=cal(i,0);
int tp2=cal(i,1);
if(tp1>tp2) ans1+='1',ans2+='0';
else if(tp1<tp2) ans1+='0',ans2+='1';
else ans1+='0',ans2+='0';
}
cout<<ans1<<endl<<ans2<<endl;
return;
}
int main()
{
ios::sync_with_stdio(false);
int t = 1;
while(t--){
solve();
}
return 0;
}