#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <stack>
#include <utility>
#include <cstdlib>

using namespace std;
typedef long long ll;

class Rational {

private:
	ll n, d;

	void reduce(){
		ll gcd = __gcd(llabs(n), llabs(d));
		n /= gcd; d /= gcd;
		if(d < 0){ n = -n; d = -d; }
	}

public:
	Rational(ll nume = 0, ll deno = 1) : n(nume), d(deno) { reduce(); }

	int nume() const { return n; }
	int deno() const { return d; }

	Rational operator+(const Rational &r) const {
		return Rational(n * r.d + r.n * d, d * r.d);
	}
	Rational &operator+=(const Rational &r){ return *this = *this + r; }

	Rational operator-(const Rational &r) const {
		return Rational(n * r.d - r.n * d, d * r.d);
	}
	Rational &operator-=(const Rational &r){ return *this = *this - r; }

	Rational operator*(const Rational &r) const {
		return Rational(n * r.n, d * r.d);
	}
	Rational &operator*=(const Rational &r){ return *this = *this * r; }

	Rational operator/(const Rational &r) const {
		return Rational(n * r.d, d * r.n);
	}
	Rational &operator/=(const Rational &r){ return *this = *this / r; }

	bool operator<(const Rational &r) const { return n * r.d < r.n * d; }
	bool operator<=(const Rational &r) const { return n * r.d <= r.n * d; }
	bool operator>(const Rational &r) const { return n * r.d > r.n * d; }
	bool operator>=(const Rational &r) const { return n * r.d >= r.n * d; }

};

const int MAX_N = 10000000;

bitset<MAX_N> sieve;
vector<int> primes;
void eratosthenes(){
	sieve[0] = sieve[1] = true;
	for(int i = 2; i < MAX_N; ++i){
		if(sieve[i]){ continue; }
		primes.push_back(i);
		for(int j = i + i; j < MAX_N; j += i){ sieve[j] = true; }
	}
}

typedef vector< pair<ll, Rational> > Value;

bool disp(const Rational &r){
	if(r.nume() == 1 && r.deno() == 1){ return false; }
	if(r.nume() == -1 && r.deno() == 1){ cout << "-"; return false; }
	if(r.deno() == 1){
		cout << r.nume();
	}else{
		cout << r.nume() << "/" << r.deno();
	}
	return true;
}

void disp(const Value &x){
	if(x.empty()){
		cout << "0" << endl;
		return;
	}
	for(int i = 0; i < x.size(); ++i){
		if(x[i].first == 1){
			if(!disp(x[i].second)){ cout << "1"; }
		}else{
			if(disp(x[i].second)){ cout << "*"; }
			cout << "sqrt(" << x[i].first << ")";
		}
		if(i + 1 != x.size()){ cout << " + "; }
	}
	cout << endl;
}

pair<ll, ll> split(ll x){
	ll first = 1ll;
	for(int i = 0; i < primes.size() && primes[i] <= x; ++i){
		ll p = primes[i], p2 = p * p;
		while(x % p2 == 0){
			x /= p2;
			first *= p;
		}
	}
	return make_pair(first, x);
}

int main(){
	ios_base::sync_with_stdio(false);
	eratosthenes();
	stack<Value> s;
	while(true){
		string command;
		cin >> command;
		if(command == "push"){
			ll n;
			cin >> n;
			Value v;
			v.push_back(make_pair(1ll, Rational(n)));
			s.push(v);
		}else if(command == "add"){
			Value x1 = s.top(); s.pop();
			Value x0 = s.top(); s.pop();
			map<ll, Rational> m;
			for(int i = 0; i < x0.size(); ++i){ m.insert(x0[i]); }
			for(int i = 0; i < x1.size(); ++i){
				m[x1[i].first] += x1[i].second;
			}
			Value y;
			for(map<ll, Rational>::iterator it = m.begin(); it != m.end(); ++it){
				if(it->second.nume() != 0){ y.push_back(*it); }
			}
			s.push(y);
		}else if(command == "sub"){
			Value x1 = s.top(); s.pop();
			Value x0 = s.top(); s.pop();
			map<ll, Rational> m;
			for(int i = 0; i < x0.size(); ++i){ m.insert(x0[i]); }
			for(int i = 0; i < x1.size(); ++i){
				m[x1[i].first] -= x1[i].second;
			}
			Value y;
			for(map<ll, Rational>::iterator it = m.begin(); it != m.end(); ++it){
				if(it->second.nume() != 0){ y.push_back(*it); }
			}
			s.push(y);
		}else if(command == "mul"){
			Value x1 = s.top(); s.pop();
			Value x0 = s.top(); s.pop();
			map<ll, Rational> m;
			for(int i = 0; i < x0.size(); ++i){
				for(int j = 0; j < x1.size(); ++j){
					pair<ll, ll> sval = split(x0[i].first * x1[j].first);
					Rational rval = x0[i].second * x1[j].second * sval.first;
					m[sval.second] += rval;
				}
			}
			Value y;
			for(map<ll, Rational>::iterator it = m.begin(); it != m.end(); ++it){
				if(it->second.nume() != 0){ y.push_back(*it); }
			}
			s.push(y);
		}else if(command == "div"){
			Value x1 = s.top(); s.pop();
			Value x0 = s.top(); s.pop();
			map<ll, Rational> m;
			for(int i = 0; i < x0.size(); ++i){
				for(int j = 0; j < x1.size(); ++j){
					pair<ll, ll> sval = split(x0[i].first * x1[j].first);
					Rational rval = x0[i].second * sval.first;
					rval /= x1[j].second * x1[j].first;
					m[sval.second] += rval;
				}
			}
			Value y;
			for(map<ll, Rational>::iterator it = m.begin(); it != m.end(); ++it){
				if(it->second.nume() != 0){ y.push_back(*it); }
			}
			s.push(y);
		}else if(command == "sqrt"){
			Value x = s.top(); s.pop();
			Value y;
			if(x[0].second.nume() != 0){
				pair<ll, ll> sval = split(x[0].second.nume() * x[0].second.deno());
				Rational rval = Rational(1, x[0].second.deno()) * sval.first;
				y.push_back(make_pair(sval.second, rval));
			}else{
				y.push_back(make_pair(1ll, Rational(0)));
			}
			s.push(y);
		}else if(command == "disp"){
			disp(s.top());
			s.pop();
		}else if(command == "stop"){
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 4912