The Frustrated Sam
Difficulty: Hard

This is placement season. _Sam_ got frustated because of his batch mates. They all have a good OGPA. Odds are not in favor of _Sam_. But _Sam_ have a cool idea of project that will get him into any dream company. Project is calculation of frustration among engineers. So after a lot of research he formulated measure of frustration as follows:  

$\ \ \ \ A(n) = a_{1} \cdot A(n - 1) + b_{1} \cdot B(n - 1) + c_{1}$  
$\ \ \ \ B(n) = a_{2} \cdot A(n - 1) + b_{2} \cdot B(n - 1) + c_{2}$  

As value of $n$ will be larged please help _Sam_ to calculate $A(n)$ and $B(n)$ and get a good job. Given that $A(1) = 1$ and $B(1) = 2$.

**INPUT**  
First line will contain single integer $T$, number of test cases.  
After that Each line will follow $7$ integers $a_{1}, b_{1}, c_{1}, a_{2}, b_{2}, c_{2}, n$  

**OUTPUT**  
For each testcase, print in a newline, two integers separated by single space i.e. value of $A(n)$ and $B(n)$.  
As value of $A(n)$ and $B(n)$ can be really large, output them by taking modulo $1000000007$.  

**CONSTRAINTS**  
$1 <= T <= 10^4$    
$1 <= a_{1}, b_{1}, c_{1}, a_{2}, b_{2}, c_{2} <= 10$  
$1 <= n <= 10^{12}$  


**Sample Input**  

    2  
    1 2 3 4 5 6 3  
    1 2 3 4 5 6 5  

**Sample Output**  

    51 138
	2133 5826


Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:


Reference solution (Python):
    import java.io.*;
    import java.util.StringTokenizer;

    class Matrix {

        public static long mod = 1000000007;
        public final long[][] data;
        public final int rowCount;
        public final int columnCount;

        public Matrix(int rowCount, int columnCount) {
            this.rowCount = rowCount;
            this.columnCount = columnCount;
            this.data = new long[rowCount][columnCount];
        }

        public static Matrix multiply(Matrix first, Matrix second) {
            Matrix result = new Matrix(first.rowCount, second.columnCount);
            for (int i = 0; i < first.rowCount; i++) {
                for (int j = 0; j < second.rowCount; j++) {
                    for (int k = 0; k < second.columnCount; k++)
                        result.data[i][k] = (result.data[i][k] + first.data[i][j] * second.data[j][k]) % mod;
                }
            }
            return result;
        }

        public static Matrix identityMatrix(int size) {
            Matrix result = new Matrix(size, size);
            for (int i = 0; i < size; i++)
                result.data[i][i] = 1;
            return result;
        }

        public Matrix power(long exponent) {
            if (exponent == 0)
                return identityMatrix(rowCount);
            if (exponent == 1)
                return this;
            Matrix result = power(exponent >> 1);
            result = multiply(result, result);
            if ((exponent & 1) == 1)
                result = multiply(result, this);
            return result;
        }

    }

    public class Solution {

        static BufferedReader reader;
        static StringTokenizer st;
        static final long MOD = 1000000007;
        static long[] memo;

        public static void main(String[] args) throws IOException {
            reader = new BufferedReader(new InputStreamReader(System.in));
            int test = nextInt();
            while(test-- > 0) {
                int a1 = nextInt(), b1 = nextInt(), c1 = nextInt();
                int a2 = nextInt(), b2 = nextInt(), c2 = nextInt();
                long N = nextLong();
                Matrix offset = new Matrix(3, 3);
                offset.data[0][0] = a1; offset.data[0][1] = b1; offset.data[0][2] = c1;
                offset.data[1][0] = a2; offset.data[1][1] = b2; offset.data[1][2] = c2;
                offset.data[2][0] = 0; offset.data[2][1] = 0; offset.data[2][2] = 1;
                offset = offset.power(N - 1);
                long A = ( offset.data[0][0] * 1 + offset.data[0][1] * 2 + offset.data[0][2] * 1) % MOD;
                long B = ( offset.data[1][0] * 1 + offset.data[1][1] * 2 + offset.data[1][2] * 1) % MOD;
                System.out.println(A + " " + B);
            }
        }

        public static long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public static int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public static String next() throws IOException {
            while(st == null || !st.hasMoreTokens())
                st = new StringTokenizer(reader.readLine());
            return st.nextToken();
        }

    }