why my code is getting nzec ?

import java.util.*;
class snackdownq3practise {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T=sc.nextInt();
while(T>0)
{
int N= sc.nextInt();
int A[] = new int[N];
for(int i=0;i<N;i++)
A[i] = sc.nextInt();
int count=0;
int x = 1;

         for(int i=1;i<N;i++)
             A[i]=A[i]+A[i-1];
         
      for(int i=0;i<N;i++){
            x = x+A[x-1];
            
            count++;
            if(x>=N)
                break;
        }
        System.out.println(count);
        T--;
        
    }
    
}

}