LINQSOLV  Linear Equation Solver
Given a system of linear equations, print the solution of that system.
Input
Input starts with a positive integer t<100 in a single line, then t testcases follow. Every testcase represents a linear system and starts with one line containing a positive integer n<21, the number of equations and also the number of variables of that system. Then n equations follow, each one in a single line.
An equation is written in schoolbook notation, i.e. variables noted by single small letters (english alphabet), no multiplication sign, factor 1 left out, no spaces in between. A variable or a value may occur zero or more times in an equation. All coefficients are integers with an absolute value less than 100, a single line won't be longer than 100 characters and will always contain a valid linear equation.
The following equations are considered to be valid:
a+bc+b2ca=1 x+59=4x+y8 cc+t+1=0 y=z
The following equations are considered to be invalid:
4*a+b=6 6+2x=99 cc+tt=0 4+9 = h
Output
For each testcase print all variables of the linear system in alphabetical order together with the associated value as an integer or a fraction in lowest terms respectively. Print a blank line between testcases. For exact notation see example below. All (interim) results will fit into 64bit, if algorithm is implemented properly. You can assume that all linear systems have an unique solution.
Example
Input: 2 2 a+b=5 ba=1 3 5u5z+4=0 8k3z=2 9ku=u Output: a=2 b=3 k=4/55 u=18/55 z=26/55
hide comments
Simes:
20191020 20:53:27
Thoroughly enjoyed solving it, thank you!

Added by:  numerix 
Date:  20110314 
Time limit:  0.5s 
Source limit:  10000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All 
Resource:  own problem 