#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_STACK = 256;

/* typedef */

struct Rational {
  int sign, n, d;
  Rational(): sign(1), n(0), d(1) {}
  Rational(int _n): sign(1), n(_n), d(1) { normalize(); }
  Rational(int _n, int _d): sign(1), n(_n), d(_d) { normalize(); }

  void normalize() {
    if (d == 0) return;
    if (n == 0) {
      sign = d = 1;
      return;
    }
    if (d < 0) sign = -sign, d = -d;
    if (n < 0) sign = -sign, n = -n;
    int g = __gcd(n, d);
    if (g != 1) n /= g, d /= g;
  }

  bool iszero() { return n == 0; }
  bool nonzero() { return n != 0; }
  
  Rational operator-() {
    return Rational(-sign * n, d);
  }

  Rational operator+(const Rational r0) {
    return Rational(sign * n * r0.d + r0.sign * r0.n * d, d * r0.d);
  }

  Rational operator-(const Rational r0) {
    return Rational(sign * n * r0.d - r0.sign * r0.n * d, d * r0.d);
  }

  Rational operator*(const Rational r0) {
    return Rational(sign * n * r0.sign * r0.n, d * r0.d);
  }

  Rational operator/(const Rational r0) {
    return Rational(sign * n * r0.sign * r0.d, d * r0.n);
  }

  static int _qdiv(int r) {
    int maxqd = 1;
    for (int qd = 2; qd * qd <= r; qd++)
      if (r % (qd * qd) == 0) maxqd = qd;
    return maxqd;
  }
  
  Rational sqrt(int& r) {
    int nq = _qdiv(n);
    int dq = _qdiv(d);
    int nr = n / (nq * nq);
    int dr = d / (dq * dq);

    r = nr * dr;
    int n1 = sign * nq;
    int d1 = dq * dr;

    int rq = _qdiv(r);
    if (rq > 1) {
      r /= (rq * rq);
      n1 *= rq;
    }
    return Rational(n1, d1);
  }

  string to_s() {
    stringstream ss;
    if (sign < 0) ss << '-';
    ss << n;
    if (d != 1) ss << '/' << d;
    return ss.str();
  }
};

typedef pair<int,Rational> pir;
typedef map<int,Rational> mir;

struct XStar {
  mir qrs;
  XStar() {}
  XStar(int n) { if (n != 0) qrs[1] = Rational(n); }
  XStar(int r, Rational rt) { if (rt.n != 0) qrs[r] = rt; }
  XStar(mir _qrs): qrs(_qrs) {}

  XStar operator+(XStar x0) {
    mir qrs1(qrs);
    for (mir::iterator qit0 = x0.qrs.begin(); qit0 != x0.qrs.end(); qit0++) {
      mir::iterator qit1 = qrs1.find(qit0->first);
      if (qit1 == qrs1.end())
	qrs1[qit0->first] = qit0->second;
      else {
	Rational rt1 = qit1->second + qit0->second;
	if (rt1.nonzero()) qrs1[qit0->first] = rt1;
	else qrs1.erase(qit1);
      }
    }
    return XStar(qrs1);
  }

  XStar operator-(XStar x0) {
    mir qrs1(qrs);
    for (mir::iterator qit0 = x0.qrs.begin(); qit0 != x0.qrs.end(); qit0++) {
      mir::iterator qit1 = qrs1.find(qit0->first);
      if (qit1 == qrs1.end())
	qrs1[qit0->first] = -qit0->second;
      else {
	Rational rt1 = qit1->second - qit0->second;
	if (rt1.nonzero()) qrs1[qit0->first] = rt1;
	else qrs1.erase(qit1);
      }
    }
    return XStar(qrs1);
  }

  XStar operator*(XStar x0) {
    mir qrs1;
    for (mir::iterator qit = qrs.begin(); qit != qrs.end(); qit++) {
      int r = qit->first;
      Rational& rt = qit->second;
      //cout << "rt = " << rt.to_s() << endl;
      
      for (mir::iterator qit0 = x0.qrs.begin(); qit0 != x0.qrs.end(); qit0++) {
	//cout << "rt0 = " << qit0->second.to_s() << endl;
	int rr = r * qit0->first;
	Rational rrt = rt * qit0->second;
	//cout << "rrt = " << rrt.to_s() << endl;

	int rrqd = Rational::_qdiv(rr);
	if (rrqd > 1) {
	  rr /= (rrqd * rrqd);
	  rrt = Rational(rrt.sign * rrt.n * rrqd, rrt.d);
	}

	mir::iterator qit1 = qrs1.find(rr);
	if (qit1 == qrs1.end())
	  qrs1[rr] = rrt;
	else {
	  rrt = qit1->second + rrt;
	  if (rrt.nonzero()) qrs1[rr] = rrt;
	  else qrs1.erase(qit1);
	}
      }
    }
    return XStar(qrs1);
  }

  XStar inv() {
    //cout << "inv: "; print();
    mir qrs1;
    for (mir::iterator qit = qrs.begin(); qit != qrs.end(); qit++) {
      int r = qit->first;
      Rational& rt = qit->second;
      qrs1[r] = Rational(rt.sign * rt.d, rt.n * r);
    }
    //cout << "  -> "; XStar(qrs1).print();
    return XStar(qrs1);
  }
  
  void print() {
    if (qrs.empty()) {
      cout << 0 << endl;
      return;
    }

    bool first = true;
    for (mir::iterator qit = qrs.begin(); qit != qrs.end(); qit++) {
      if (! first) cout << " + ";

      int r = qit->first;
      Rational& rt = qit->second;

      if (r == 1) cout << rt.to_s();
      else {
	if (rt.d == 1 && rt.n == 1) {
	  if (rt.sign < 0) cout << '-';
	}
	else cout << rt.to_s() << '*';
	cout << "sqrt(" << r << ")";
      }
      first = false;
    }
    cout << endl;
  }
};

/* global variables */

stack<XStar> stk;

/* subroutines */

/* main */

int main() {
  for (;;) {
    string op;
    cin >> op;
    //cout << op << ":" << endl;
    
    if (op == "push") {
      int n;
      cin >> n;

      if (stk.size() < MAX_STACK) stk.push(XStar(n));
      //stk.top().print();
    }
    else if (op == "add") {
      XStar x1 = stk.top(); stk.pop();
      XStar x2 = stk.top(); stk.pop();
      stk.push(x2 + x1);
      //stk.top().print();
    }
    else if (op == "sub") {
      XStar x1 = stk.top(); stk.pop();
      XStar x2 = stk.top(); stk.pop();
      stk.push(x2 - x1);
      //stk.top().print();
    }
    else if (op == "mul") {
      XStar x1 = stk.top(); stk.pop();
      XStar x2 = stk.top(); stk.pop();
      stk.push(x2 * x1);
      //stk.top().print();
    }
    else if (op == "div") {
      XStar x1 = stk.top(); stk.pop();
      //cout << "x1 = "; x1.print();
      XStar x2 = stk.top(); stk.pop();
      //cout << "x2 = "; x2.print();
      //cout << "x1.inv = "; x1.inv().print();
      stk.push(x2 * x1.inv());
      //stk.top().print();
    }
    else if (op == "sqrt") {
      XStar x1 = stk.top(); stk.pop();
      //cout << "sqrt: x1 = "; x1.print();

      if (x1.qrs.find(1) == x1.qrs.end())
	stk.push(XStar());
      else {
	int r = 1;
	Rational rt0 = x1.qrs[1].sqrt(r);
	stk.push(XStar(r, rt0));
	//cout << "sqrt(x1) = "; stk.top().print();
	//stk.top().print();
      }
    }
    else if (op == "disp") {
      XStar x1 = stk.top(); stk.pop();
      x1.print();
    }
    else if (op == "stop") break;
  }

  return 0;
}

Measured memory_bytes: 1256