How to shift a matrix by x rows and y columns in the most efficient way?
I could think of a time-efficient solution which is not good in terms of memory. 

We will carry out duplication of the given array. 

For eg. 

Initial Array:



We can have 4 duplicate copies of the same array, each attached to form a huge square. 

Big Array looks like:



Within this Big Array, let me call my result as the Result Array. 

Initially, when we have no rotation involved, the result array looks like:



The Blue colored box represents the result array. 

The top_left_index of the result array = (0, 0). [Image above]

After that, suppose we rotate 1 row, the blue colored box shifts down as follows:



The top_left_index of the result array = (1, 0). [Image above]

After that, suppose we rotate 1 column, the blue colored box shifts right as follows:



The top_left_index of the result array becomes = (1, 1). [Image above]

After that, suppose we rotate 1 row, the blue colored box shifts down as follows:



The top_left_index of the result array becomes = (2, 1). [Image above]

After that, suppose we rotate 2 cols, the blue colored box shifts right as follows:



The top_left_index of the result array becomes = (2, 3). [Image above]

This is how the entire logic works. 

We just need to store the top left index of the blue box. Whenever asked for the result, we can display the elements of the blue-colored box. 

So, the entire problem boils down to calculating the top left index of the blue box. 

Time Complexity of changing the index: O(1)

Space complexity: O(n^2)

However, there exist corner cases that need to be handled. Once such corner case is as below:



Handling this corner case is not difficult. In case we feel that the resultant array's bounds are overflowing the boundary of the Big array, we need to reduce the value of our top_left_index such that the entire square fits in the array. 
For eg., 

In the above image, the top_left_index (2,4) overflows the bounds of Big Array. 

We simply reduce the overflowing index by the respective dimension of our original array and make it:

(2, 4 - 3 ) = (2, 1).

Now, things look beautiful again.