Why am i getting run time error?

Code:
#include
#include
using namespace std;

int main(){
int t;
cin >> t;
while (t–){
int n, *arr = new int[n];
cin >> n;
for (int i =0; i < n; i++){
cin >> arr[i];
}
next_permutation(arr, arr+n);
for (int i=0; i < n; i++){
cout << arr[i] << " ";
}
cout << “\n”;
}
return 0;
}

@adityakaunhai

u are declaring
arr= new int[n]
before taking the value of n from user

slide the arr line below the cin >> n