Language: C++

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

#define loop(i,a,b) for(int i=a;i<(int)(b);i++)
#define rep(i,b) loop(i,0,b)
typedef long long ll;

// 1 indexed

int main(){
    ll N;
    while(cin >> N && N){
        ll a,d;
        ll M;
        cin >> a >> d >> M;
        vector<ll> x(M), y(M), z(M);
        ll k;

        auto kth = [&](ll k){
            ll res = a;
            rep(i,k-1){
                res += d;
            }
            return res;
        };

        rep(i,M) cin >> x[i] >> y[i] >> z[i];
        set<int> s;
        s.insert(y.begin(), y.end());
        s.insert(z.begin(), z.end());
        cin >> k;

        // rep(i,5){
        //     cout << kth(i+1) << " ";
        // }
        // cout << endl;

        ll ans = -1;
        if(s.count(k)){
            map<ll,ll> m;
            for(int i : s) m[i] = i;
            rep(i,M){
                if(x[i] == 0){
                    swap(m[y[i]],m[z[i]]);
                } else {
                    m[y[i]] = m[z[i]];
                }
            }
            ans = kth(m[k]);
        } else {
            ans = kth(k);
        }
        cout << ans << endl;
    }
}

Compiler output:
a.cc:1:2: error: stray '#' in program
    1 | w#include <bits/stdc++.h>
      |  ^
a.cc:1:1: error: 'w' does not name a type
    1 | w#include <bits/stdc++.h>
      | ^
a.cc: In function 'int main()':
a.cc:12:11: error: 'cin' was not declared in this scope
   12 |     while(cin >> N && N){
      |           ^~~
a.cc:16:9: error: 'vector' was not declared in this scope
   16 |         vector<ll> x(M), y(M), z(M);
      |         ^~~~~~
a.cc:16:18: error: expected primary-expression before '>' token
   16 |         vector<ll> x(M), y(M), z(M);
      |                  ^
a.cc:16:20: error: 'x' was not declared in this scope
   16 |         vector<ll> x(M), y(M), z(M);
      |                    ^
a.cc:16:26: error: 'y' was not declared in this scope
   16 |         vector<ll> x(M), y(M), z(M);
      |                          ^
a.cc:16:32: error: 'z' was not declared in this scope
   16 |         vector<ll> x(M), y(M), z(M);
      |                                ^
a.cc:28:9: error: 'set' was not declared in this scope
   28 |         set<int> s;
      |         ^~~
a.cc:28:13: error: expected primary-expression before 'int'
   28 |         set<int> s;
      |             ^~~
a.cc:29:9: error: 's' was not declared in this scope
   29 |         s.insert(y.begin(), y.end());
      |         ^
a.cc:40:13: error: 'map' was not declared in this scope
   40 |             map<ll,ll> m;
      |             ^~~
a.cc:40:19: error: expected primary-expression before ',' token
   40 |             map<ll,ll> m;
      |                   ^
a.cc:40:22: error: expected primary-expression before '>' token
   40 |             map<ll,ll> m;
      |                      ^
a.cc:40:24: error: 'm' was not declared in this scope
   40 |             map<ll,ll> m;
      |                        ^
a.cc:44:21: error: 'swap' was not declared in this scope
   44 |                     swap(m[y[i]],m[z[i]]);
      |                     ^~~~
a.cc:53:9: error: 'cout' was not declared in this scope
   53 |         cout << ans << endl;
      |         ^~~~
a.cc:53:24: error: 'endl' was not declared in this scope
   53 |         cout << ans << endl;
      |                        ^~~~