Exist or not hashing

although the output is correct test cases are not passing

@ayu2321 you have to take input for EVERY test case.
cin >> t
while(t–) {
…all your code logic should be here
}

Just try to run for 2 test cases and you will see the mistake

i have used for loop for test cases

@ayu2321 you took input for n before that

it is giving segmentation fault
#include
#include<unordered_set>
using namespace std;

int main() {
int t;
cin>>t;
int n,q,query;

int arr[n];
unordered_set<int>s;

for(int i=0;i<t;i++){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		s.insert(arr[i]);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>query;
		if(s.find(query)==s.end()){
			cout<<"No"<<endl;
		}
		else{
			cout<<"Yes"<<endl;
		}
	}

}
return 0;

}

@ayu2321 how can you use same variable i to traverse nested loops? Here is the corrected code : https://ide.codingblocks.com/s/294673

@ayu2321 and you declared arr[n] without knowing the value of n beforehand

now i hav taken 2 test cases and it is giving correct output then also test cases are not passing
input
2
2
12 3
2
12
5
2
1 2
2
1
2

@ayu2321 arr[n] you have declared but input for n you are taking later. See the code that I sent please

i have seen that code but i am not understanding my mistake
#include
#include<unordered_set>
using namespace std;

int main() {
int t;
cin>>t;
int n,q,query;

int arr[100003];
unordered_set<int>s;

for(int i=0;i<t;i++){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>arr[i];
		s.insert(arr[i]);
	}
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>query;
		if(s.find(query)==s.end()){
			cout<<"No"<<endl;
		}
		else{
			cout<<"Yes"<<endl;
		}
	}

}
return 0;

}

@ayu2321 please see my above replies I have pointed al the mistakes.

see this part, you cant use the same variable in nested loops.
you are using i below as well.

hi
is this also incorrect

@ayu2321 n has garbage value at this point
image

@ayu2321 put this line after you take input for n, rest everything is fine

if i put the range of array as specified by thr constraints in the ques

@ayu2321 This is also correct. But remember this will take up more space than required.

@ayu2321 make sure your set is emptied for each test case

okay thank you so much for clearing these basic concepts so well…but that code is also not passing all the test cases

@ayu2321 did you empty the set after each test case? It will have some values from previous test cases that may not be there in present test case and might give wrong answer for queries

@ayu2321 this is why its better to work in local scope so you dont have to worry about things like re-initializing the variables for each loop