#include <cstdio>
#include <vector>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, q, pcnt, V, a[ 100009 ] , b[ 100009 ] , c[ 100009 ] , perm[ 50009 ] , idx[ 50009 ] ; long long bit[ 50009 ] [ 785 ] ; bool used[ 50009 ] ; vector< int > g[ 50009 ] , rg[ 50009 ] , G[ 50009 ] ;
void dfs1( int pos) {
used[ pos] = true ;
for ( int i : g[ pos] ) {
if ( ! used[ i] ) dfs1( i) ;
}
perm[ pcnt++ ] = pos;
}
void dfs2( int pos) {
idx[ pos] = V; used[ pos] = true ;
for ( int i : rg[ pos] ) {
if ( ! used[ i] ) dfs2( i) ;
}
}
int main( ) {
scanf ( "%d %d" , & n, & m) ;
for ( int i = 0 ; i < m; i++ ) {
scanf ( "%d %d" , & a[ 0 ] , & b[ 0 ] ) ;
g[ -- a[ 0 ] ] .push_back ( -- b[ 0 ] ) ;
rg[ b[ 0 ] ] .push_back ( a[ 0 ] ) ;
}
scanf ( "%d" , & q) ;
for ( int i = 0 ; i < q; i++ ) {
scanf ( "%d %d %d" , & a[ i] , & b[ i] , & c[ i] ) ; b[ i] -- ;
if ( a[ i] == 2 ) c[ i] -- ;
else {
if ( c[ i] == 0 ) {
rg[ n] .push_back ( b[ i] ) ;
g[ b[ i] ] .push_back ( n++ ) ;
}
else {
rg[ b[ i] ] .push_back ( n) ;
g[ n++ ] .push_back ( b[ i] ) ;
}
}
}
for ( int i = 0 ; i < n; i++ ) {
if ( ! used[ i] ) dfs1( i) ;
}
fill( used, used + n, false ) ;
for ( int i = n - 1 ; i >= 0 ; i-- ) {
if ( ! used[ perm[ i] ] ) dfs2( perm[ i] ) ;
V++ ;
}
for ( int i = 0 ; i < n; i++ ) {
for ( int j : g[ i] ) {
if ( idx[ i] ! = idx[ j] ) {
G[ idx[ i] ] .push_back ( idx[ j] ) ;
}
}
}
for ( int i = V - 1 ; i >= 0 ; i-- ) {
bit[ i] [ i >> 6 ] | = 1LL << ( i & 63 ) ;
for ( int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