// G. Hagopian -- Kattis Add Words

/*
def foo 3
calc foo + bar =
def bar 7
def programming 10
calc foo + bar =
def is 4
def fun 8
calc programming - is + fun =
def fun 1
calc programming - is + fun =
clear
def dog 2
def cat 3
def catdog 5
calc cat + dog =
*/

//const int flag = -100000;
bool debug = false;

#include <iostream>
#include <vector>
#include <unordered_map>
#include <string>
#include <sstream>

using namespace std;

typedef unordered_map<string, int> SVariables;
typedef unordered_map<int, string> IVariables;

int main() {
	SVariables vars;
	IVariables vari;
	SVariables::iterator varsIter;
	IVariables::iterator variIter;

	char oper{};
	string s, token, var, output;
	int x{};

	while (getline(cin, s)) {
		bool computable = true, done = false;
		istringstream is{ s };
		is >> token;
		if (token == "def") {
			is >> var >> x;
			//if this variable already has a value
			if (vars.find(var) != vars.end())
				vari.erase(vars[s]); //erase it
			vars[var] = x; //in any case
			vari[x] = var; //maintain both maps
		}
		else if (token == "calc") {
			int left{}; //to accumulate value of expression
			is >> var; // first variable
			computable = true;
			//output += var;
			if (vars.find(var) == vars.end()) //variable is in map
				computable = false;
			else left = vars[var];
			cout << var << " ";
			while (true) {
				is >> oper;
				//output += " ";
				//output += oper;
				//cout << "output = " << output << endl;
				cout << oper << " ";
				if (oper == '=') break;
				bool plus = (oper == '+');
				is >> var;
				//output += (" " + var);
				cout << var << " ";
				//cout << "oper = " << oper << endl;
				if (vars.find(var) == vars.end()) //variable isn't in map
					computable = false;
				else if (plus) left += vars[var];
				else left -= vars[var];
			} //broke out of while because "="
			if (!computable || vari.find(left) == vari.end())
				cout << "unknown\n";
			else cout << vari[left] << endl;
		}
		else {
			output = "";
			vars.clear();
			vari.clear();
		}
	}
}