Node TransformationalQuery(Node n, ArrayList<String> kw)
		{
			exp = new Node(n);
			steps.clear();
			
			do
			{
				AFL.clear();
				steps.add(exp.infix());
				int max = 0;

                for (DynamicFormula aKB : KB) {
                    if (aKB.q_simplify(exp))        //if it is applicable
                    {
                        int matches = 0;
                        for (String aKw : kw) {
                            for (int k = 0; k < aKB.keywords.size(); k++) {
                                if (aKw.equals(aKB.keywords.get(k))) {
                                    matches++;
                                }
                            }
                        }
                        //		System.out.println(KB.get(i).isRecursive());
                        if (aKB.isRecursive()) {
                            AFL.add(aKB);            //add recursive DynamicFormula at end (least priority)
                        } else if (matches >= max)        //if max keyword matches (best option)
                        {
                            AFL.add(0, aKB);        //insert at first position
                            max = matches;                //update max
                        } else
                            AFL.add(aKB);            //else insert at end
                    }
                }
				
				//apply best match DynamicFormula
				if(AFL.size() > 0)
				{
					exp = AFL.get(0).simplify(exp);
				//	System.out.println(exp.DisplayDepthFirst());
				}
				System.out.println(exp.infix());
			}while(AFL.size() > 0);
			
			ArithmeticSolver.simplifySolve(exp);
			return exp;
		}