#include <iostream>
using namespace std;
#include<map>
#include<cmath>
#include<algorithm>
int gcd (int a,int b) {
if(b==0)
return 1;
if(a%b==0)
return b;
else
return gcd(b,a%b);
}
int main()
{
int n;
cin>>n;
map < pair < int,int > , int > m;
vector < pair < int,int > > v;
for(int i=0;i<n;i++) {
v.push_back(make_pair(0,0));
int a,b,c;
cin>>a>>b>>c;
if(a<0&&b<0) {
a=-1*a;
b=-1*b;
} else if(b<0) {
a=-1*a;
b=-1*b;
}
int x = gcd(abs(a),abs(b));
a=a/x;
b=b/x;
if(b==0)
a=1;
if(a==0)
b=1;
if(m.find(make_pair(a,b))==m.end()){
m[make_pair(a,b)]=1;
} else {
m[make_pair(a,b)]++;
}
v[i].first=a;
v[i].second=b;
}
int q;
cin>>q;
while(q--){
int x;
cin>>x;
x--;
int a=v[x].first;
int b=v[x].second;
if(a>0) {
b=-1*b;
} else {
a=-1*a;
}
if(m.find(make_pair(b,a))==m.end()){
cout<<0<<endl;
} else {
cout<<m[make_pair(b,a)]<<endl;
}
}
}
Language: C++