#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

template<class t>
t sq(t x){
	return x*x;
}


using ld=long double;
const ld eps=1e-10;
int sgn(ld a){return a<-eps?-1:(a>eps?1:0);}

struct pos{
	ld x,y,z;
	ld length(){
		return sqrt(length2());
	}
	ld length2(){
		return sq(x)+sq(y)+sq(z);
	}
	pos operator-(pos r)const{
		return {x-r.x,y-r.y,z-r.z};
	}
	bool operator<(pos r)const{
		return make_tuple(sgn(x-r.x),sgn(y-r.y),sgn(z-r.z))<make_tuple(0,0,0);
	}
	bool operator==(pos r)const{
		return make_tuple(sgn(x-r.x),sgn(y-r.y),sgn(z-r.z))==make_tuple(0,0,0);
	}
	pos operator/(ld r)const{
		return pos{x/r,y/r,z/r};
	}
};

ostream& operator<<(ostream& os,pos p){
	return os<<"{"<<p.x<<","<<p.y<<","<<p.z<<"}";
}

ld dot(pos a,pos b){
	return a.x*b.x+a.y*b.y+a.z*b.z;
}

pos cross(pos a,pos b){
	return {
		a.z*b.y-a.y*b.z,
		a.x*b.z-a.z*b.x,
		a.y*b.x-a.x*b.y,
	};
}

bool collinear(pos a,pos b,pos c){
	return sgn(cross(b-a,c-a).length2())==0;
}

struct ysp{
	vc<pos> ps;
	vc<pi> es;
	bool col;
	int n;
	void init(int nn,int k){
		n=nn;
		rep(i,n){
			ld x,y,z;cin>>x>>y>>z;
			ps.pb(pos{x,y,z});
		}
		rep(_,n-1){
			int a,b;cin>>a>>b;
			a--;b--;
			a-=k*n;
			b-=k*n;
			es.eb(a,b);
			es.eb(b,a);
		}
		col=true;
		rep(i,es.size())rep(j,es.size())if(i!=j){
			if(es[i].a==es[j].a){
				dmp(es[i]);
				dmp(es[j]);
				if(!collinear(ps[es[i].a],ps[es[i].b],ps[es[j].b])){
					col=false;
					break;
				}
			}
		}
	}
	pair<vc<pos>,vc<pi>> waf(int r,int s,int t){
		pos rs=ps[s]-ps[r];
		ld len=rs.length();
		rs=rs/len;
		pos rt=(ps[t]-ps[r])/len;
		pos nr=cross(rs,rt);
		dmp(nr);
		vc<pos> z;
		rep(i,n){
			pos w=(ps[i]-ps[r])/len;
			z.pb(pos{dot(rs,w),dot(rt,w),dot(nr,w)});
		}
		vc<pos> srt=z;
		sort(all(srt));
		vc<pi> tmp;
		for(auto e:es){
			if(e.a<e.b){
				int a=lower_bound(all(srt),z[e.a])-srt.bg;
				int b=lower_bound(all(srt),z[e.b])-srt.bg;
				if(a>b)swap(a,b);
				tmp.eb(a,b);
			}
		}
		sort(all(tmp));
		dmp(r);
		dmp(s);
		dmp(t);
		dmp(srt);
		dmp(tmp);
		return {srt,tmp};
	}
	pair<vc<pos>,vc<pi>> getone(){
		rep(i,es.size())rep(j,es.size())if(i!=j){
			if(es[i].a==es[j].a){
				if(col||!collinear(ps[es[i].a],ps[es[i].b],ps[es[j].b])){
					dmp(es[i].a);
					dmp(es[i].b);
					dmp(es[j].b);
					return waf(es[i].a,es[i].b,es[j].b);
				}
			}
		}
	}
	int enumcheck(pair<vc<pos>,vc<pi>> tar){
		int ans=0;
		rep(i,es.size())rep(j,es.size())if(i!=j){
			if(es[i].a==es[j].a){
				if(col||!collinear(ps[es[i].a],ps[es[i].b],ps[es[j].b])){
					auto cur=waf(es[i].a,es[i].b,es[j].b);
					if(cur==tar)
						ans++;
				}
			}
		}
		return ans;
	}
};

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n;cin>>n;
	ysp y[2];
	rep(k,2)
		y[k].init(n,k);
	
	int ans=0;
	if(y[0].col!=y[1].col){
	}else{
		auto base=y[0].getone();
		dmp(base);
		ans=y[1].enumcheck(base);
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3408