#include #define SIZE 1000 #define NUM 400 void swap(int* a, int* b) { if (a == b) return; *a ^= *b; *b ^= *a; *a ^= *b; } int main() { int i, N, K, Q, A[200001], B[200001]; scanf("%d %d %d", &N, &K, &Q); for (i = 1; i <= K; i++) scanf("%d %d", &(A[K-i]), &(B[K-i])); int j, k = K / SIZE; static int block[NUM][400001], tmp[400001]; for (i = 0; i < k; i++) { for (j = 1; j <= N; j++) tmp[j] = j; for (j = 0; j < SIZE && j + i * SIZE < K; j++) swap(&(tmp[A[j+i*SIZE]]), &(tmp[B[j+i*SIZE]])); for (j = 1; j <= N; j++) block[i][tmp[j]] = j; } int q, L, R, X; for (q = 1; q <= Q; q++) { scanf("%d %d %d", &L, &R, &X); L = K - R; R = K - L; for (j = L; j <= R && j % SIZE != 0; j++) { if (X == A[j]) X = B[j]; else if (X == B[j]) X = A[j]; } if (j <= R) { for (i = j / SIZE; (i + 1) * SIZE <= R; i++) X = block[i][X]; for (j = i * SIZE; j <= R; j++) { if (X == A[j]) X = B[j]; else if (X == B[j]) X = A[j]; } } printf("%d\n", X); } fflush(stdout); return 0; }