#include <stdio.h>

int main(void)
{
    int h[1000] = {};
    int p[1000] = {};
    int q[1000] = {};
    int n, m, a, i,j;
    int temp;
    int number[100] = {};

  while (1) {

    scanf("%d %d %d", &n, &m, &a);

    if(n == 0 && m == 0 && a == 0)
      break;

    for(i = 0; i < 100; i++)
      number[i] = i + 1;

    for(i = 0; i < n; i++){
      scanf("%d %d %d", &h[i], &p[i], &q[i]);
    }

    for(i = m - 1; i > 0; i--)
      for(j = 0; j < n; j++)
	if(h[j] == i - 1){
	  temp = number[p[j]-1];
	  number[p[j]-1] = number[q[j]-1];
	  number[q[j]-1] = temp;
	}

    printf("%d\n", number[n-a-1]);
  }
  return 0;
}