You on That Day

Given measured environmental factors and one-operation definitions, compute each factor's partial derivative of HAPPY and print it as a reduced fraction.

Medium6Dynamic programmingDFSMathRecursionNo attempts yetTime limit1sMemory limit512 MB

Problem

Human moods are hard to predict. Even in the same setting, reactions differ with personality and experience, and someone who cried all day may smile comfortably the next day.

Dr. Seojisu, who develops personalized AI systems, starts from one hypothesis.

"If we know the factors that shaped a person's happiness today and how those factors relate to each other, we can predict tomorrow's mood."

Factors that shape the mood fall into two kinds.

An environmental factor can be measured numerically through observation. The day's temperature, the number of friends met, and hours of sleep are examples.

A complex factor is determined by combining two different factors through one operation. For example, if study satisfaction AA equals the number of classes taken BB plus fatigue CC, it is written as A=B+CA = B + C. Happiness itself can be seen as one such complex factor.

Suppose we know today's measured values of all environmental factors and every relation between the factors. For each factor we want its influence on happiness, defined as the instantaneous rate of change of happiness with respect to that factor.

For example, let happiness HAPPYHAPPY be the product HAPPY=A×BHAPPY = A \times B of income AA and work satisfaction BB, with today's measurements A=17A = 17 and B=13B = 13. Then HAPPY=221HAPPY = 221, the influence of AA is 1313, the influence of BB is 1717, and the influence of HAPPYHAPPY on itself is 11.

Given the kinds of factors and their relations, write a program that computes the influence of every factor.

Input

The first line gives NN, the number of factors. Each of the following NN lines describes one factor.

  1. An environmental factor is given as {name} E {measured value}.
  • The name is an uppercase alphabetic string of length at most 20.
  • The measured value is an integer whose absolute value is at most 20.
  1. A complex factor is given as {name} {operation} {operand 1} {operand 2}.
  • The name is an uppercase alphabetic string of length at most 20, and happiness is always named HAPPYHAPPY.
  • The two operands are two different names among the NN factors, listed in left-hand then right-hand order.
  • The operation is one of AA (addition), SS (subtraction), MM (multiplication), and DD (division).

Every input satisfies the following.

  • Each factor value and each influence is a rational number whose reduced form has a denominator of at most 100100 million and a numerator with absolute value at most 11 billion.
  • No complex factor takes itself as an operand, and no computation refers back to itself cyclically.
  • No single factor appears as an operand in more than one complex factor.

Output

Print NN lines, one per factor, sorted by factor name in lexicographic order. Each line has the form {name} {influence}.

  • Print each influence as a reduced fraction. If the influence of MONEYMONEY is 0.25-0.25, print MONEY -1/4.
  • A factor that does not affect happiness at all has influence 00, printed as 0/1.

Hint

The second and third public test cases do not appear in the Small subtask.