Upper and lower bound of array

pls see below code and point out error,it is not printing -1 -1 for input which is not present in array.
#include
using namespace std;
int main()
{
int n,s,l,q;
int flag=1;
int arr[q],a[n];
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
cin>>q;
for(int i=0;i<q;i++){
cin>>arr[i];
}
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(arr[i]==a[j])
{

                    s=j;     
                    flag=0;                   
                    cout<< s << " ";
                    break;
                }  
            
  }           
  for(int j=n-1;j>=0;j--)
  {
            if(arr[i]==a[j])
                {
                    flag=0;
                    l=j;
                    cout<< l << endl;
                    break;
                }   
  

  }
    if(flag==1){
      cout<<"-1 -1";
  
  }


}


return 0;

}

@vidit.103 hey vidit please save your code through coding blocks ide so that I can debug your code asap.