Matrix Search: Failing all test cases

here is my code. I am confused with the input format that’s why I have just taken t=2 i.e 2 test case. I am using staircase algo. Please help.
#include
using namespace std;
int main() {
int t=2;
while(t>0)
{
int n;
cin>>n;
int m;
cin>>m;
int arr[n][m];
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
cin>>arr[i][j];
}

  }
  int a;
  cin>>a;
  int i=0;
  int j=m-1;
  int flag=0;
  while(i<=n-1 || j>=0)
  {
	  if(arr[i][j]==a)
	    {
			cout<<"1"<<endl;
            flag=1;
			break;
		}
	  else if(a<arr[i][j])
	      j--;
	  else
	      i++;
	  
  }
  if(!flag)
  {
     cout<<"0"<<endl;
  }
  t--;
}

}

hey @ayushjain.aj300, do not take any test case.Run this code without that while loop.
There are some correction in question.

Thanks for the help, sir! It worked.

hey @ayushjain.aj300 , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt as resolved

Sure sir. I will do that.