# Ninja Ant

Posted: 6 Mar, 2021

Difficulty: Moderate

#### You are given a matrix 'MAT' with ‘N’ rows and ‘N’ columns, and an ant is initially sitting on a coordinate given to you. The ant moves in an interesting way. If the ith row and jth column value are 1, it rotates 90 degrees in the right direction and moves 1 step forward. If the value at the ith row and jth column are 0, it rotates 90 degrees in the left direction and moves 1 step forward.

#### Your task is to find the final coordinates of the ant.

#### Note:

```
The ant initially faces toward the east side. Every time an ant moves from a block, it inverts it, i.e., changes 0 to 1 and 1 to 0.
If the ant exits the matrix just return -1,-1.
```

#### For example,

```
If ‘N’ = 2
mat[2][2] = {{1, 1},
{0, 0}}
startingRow = 0 , startingColumn = 0
moves = 1
The ant is initially facing the east side, it will take a right turn and move 1 stop in the south.
The output will be 1 0.
```

#### Input format :

```
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case contains four space-separated integers N, sr, and sc and moves. Where ‘N’ is the number of rows and columns in the ‘MAT’ matrix, ‘sr’ is the starting row and ‘sc’ is the starting column of the ant in the matrix, and moves are the number of moves an ant will make on the grid.
The description of the next ‘N’ lines is as follows-
Each line contains ‘N’ space-separated integers representing the elements of the matrix ‘MAT’.
```

#### Output format :

```
For each test case, print a single line containing two space-separated integers denoting the final position of an ant[0-based indexing].
The output of each test case will be printed in a separate line.
```

#### Note:

```
You do not need to print anything; it has already been taken care of. Just implement the given function.
```

#### Constraints:

```
1 <= T <= 5
1 <= N <= 100
0 <= MAT[ i ][ j ] <= 1
Where ‘T’ is the total number of test cases, and 'N’ is the number of rows and columns in the ‘MAT’ matrix, and MAT[ i ][ j ] is the value of pairs (i, j).
Time limit: 1sec.
```

SIMILAR PROBLEMS

Mining Diamonds

Posted: 4 Mar, 2022

Difficulty: Hard

Mining Diamonds

Posted: 4 Mar, 2022

Difficulty: Hard

Minimum Number of Deletions and Insertions

Posted: 4 Mar, 2022

Difficulty: Moderate

Can You Print

Posted: 14 Apr, 2022

Difficulty: Easy

Prime Digit Sum

Posted: 17 Apr, 2022

Difficulty: Hard

Prime Digit Sum

Posted: 17 Apr, 2022

Difficulty: Hard

Mario And His Princess

Posted: 12 May, 2022

Difficulty: Moderate