all the test cases passing for linear q