#include <bits/stdc++.h>   using namespace std;   template <typename T>   T in() {     char ch;     T n = 0;     bool ng = false;     while (1) {       ch = getchar();       if (ch ==  - ) {         ng = true;         ch = getchar();         break;       }       if (ch >=  0  && ch <=  9 ) break;     }     while (1) {       n = n * 10 + (ch -  0 );       ch = getchar();       if (ch <  0  || ch >  9 ) break;     }     return (ng ? -n : n);   }   template <typename T>   inline T POW(T B, T P) {     if (P == 0) return 1;     if (P & 1)       return B * POW(B, P - 1);     else       return (POW(B, P / 2) * POW(B, P / 2));   }   template <typename T>   inline T Gcd(T a, T b) {     if (a < 0) return Gcd(-a, b);     if (b < 0) return Gcd(a, -b);     return (b == 0) ? a : Gcd(b, a % b);   }   template <typename T>   inline T Lcm(T a, T b) {     if (a < 0) return Lcm(-a, b);     if (b < 0) return Lcm(a, -b);     return a * (b / Gcd(a, b));   }   long long Bigmod(long long base, long long power, long long MOD) {     long long ret = 1;     while (power) {       if (power & 1) ret = (ret * base) % MOD;       base = (base * base) % MOD;       power >>= 1;     }     return ret;   }   bool isVowel(char ch) {     ch = toupper(ch);     if (ch ==  A  || ch ==  U  || ch ==  I  || ch ==  O  || ch ==  E )       return true;     return false;   }   template <typename T>   long long int isLeft(T a, T b, T c) {     return (a.x - b.x) * (b.y - c.y) - (b.x - c.x) * (a.y - b.y);   }   long long ModInverse(long long number, long long MOD) {     return Bigmod(number, MOD - 2, MOD);   }   bool isConst(char ch) {     if (isalpha(ch) && !isVowel(ch)) return true;     return false;   }   int toInt(string s) {     int sm;     stringstream second(s);     second >> sm;     return sm;   }   char s[5007];   unordered_map<string, int> mp;   vector<string> A[5007];   int dp[5007][2001];   int n, m;   int koto(string p, int pos, int b) {     if (p[0] ==  0  || p[0] ==  1 ) return (p[pos] -  0 );     if (p[0] ==  ? ) return b;     int id = mp[p];     return dp[id][pos];   }   void solve(int pos, int b) {     for (int i = 1; i <= n; i++) {       if (A[i].size() == 3) {         dp[i][pos] = koto(A[i][2], pos, b);       } else {         int x = koto(A[i][2], pos, b);         int y = koto(A[i][4], pos, b);         if (A[i][3][0] ==  A ) x = x & y;         if (A[i][3][0] ==  O ) x = x | y;         if (A[i][3][0] ==  X ) x = x ^ y;         dp[i][pos] = x;       }     }   }   int main() {     cin >> n >> m;     getchar();     for (int i = 1; i < n + 1; i++) {       gets(s);       vector<string> v;       string tp;       int ln = strlen(s);       for (int j = 0; j < ln; j++) {         if (s[j] ==    ) {           v.push_back(tp);           tp.clear();         } else {           tp += s[j];         }       }       v.push_back(tp);       mp[v[0]] = i;       for (int j = 0; j < v.size(); j++) A[i].push_back(v[j]);     }     string x, y;     for (int i = 0; i < m; i++) {       solve(i, 0);       int cnt = 0;       for (int j = 1; j < n + 1; j++) {         cnt += dp[j][i];       }       solve(i, 1);       int cnt1 = 0;       for (int j = 1; j < n + 1; j++) {         cnt1 += dp[j][i];       }       if (cnt >= cnt1) {         y +=  0 ;       } else         y +=  1 ;       if (cnt <= cnt1) {         x +=  0 ;       } else         x +=  1 ;     }     cout << x << endl;     cout << y << endl;     return 0;   }   