#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-6)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check1(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-6)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cerr<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ll X[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
void check2(string &ans){
    for(int itr=0; itr<100; itr++)
    {
        ll mod = 1e13 + itr;
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
void check3(string &ans){
    X[n] = A[n];
    for(int i=n-1; i>=0; i--)
    {
        if( abs(X[i+1] * K) > OO )
        {
            ans = "No";
            return;
        }

        X[i] = X[i+1] * K + A[i];
    }

    if(X[0] != 0)
        ans = "No";
}
//
#define pMax 1000000
bitset <pMax + 1> isPrime;
vi prime;
void sieve(){
    isPrime.set();
    isPrime[0] = isPrime[1] = 0;

    prime.PB(2);
    for(int i=4; i<=pMax; i+=2)
        isPrime[i] = 0;

    for(int i=3; i<=pMax; i+=2)
    {
        if(isPrime[i])
        {
            prime.PB(i);
            if(1LL*i*i > pMax) continue;
            for(int j=i*i; j<=pMax; j+=i)
                isPrime[j] = 0;
        }
    }
}
void check4(string &ans){

    sieve();
    int primeSize = prime.size();
    srand( time(0) );

    for(int itr=0; itr<100; itr++)
    {
        int mod = prime[ rand()%primeSize ];
        DEBUG(mod);
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check3(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-6)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
void check2(string &ans){
    for(int itr=0; itr<1000; itr++)
    {
        ll mod = 1e13 + itr;
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check2(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define OO (1000000000)         // ToDo
#define EPS (1e-9)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define DEBUG(x) cerr<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    #define LL "%lld"
    freopen("in.in", "rt", stdin);
    if(outToFile)
    freopen("out.out", "wt", stdout);
#else
    #define LL "%I64d"
#endif
}
//
#define nMax 100000+1+9
#define vMax 10000+9
int n, K;
int A[nMax];
ll X[nMax];
ld B[nMax];
bool humanNow, humanLast, done;
int games;
//
void check(string &ans){
    ld bi = 1.0 * A[0] / -K;
    B[0] = bi;
    for(int i=1; i<=n-1; i++)
    {
        bi = (A[i] - bi)/ -K;
        B[i] = bi;
    }

    if(bi != A[n])
        ans = "No";
}
void check1(string &ans){
    int add = 0;
    for(int i=0; i<=n; i++)
    {
        if((A[i] + add)%K != 0)
        {
            ans = "No";
            return;
        }

        add = (A[i] + add)/K;
    }

    if(add != 0)
        ans = "No";
}
void check2(string &ans){
    for(int itr=0; itr<100; itr++)
    {
        ll mod = 1e13 + itr;
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
void check3(string &ans){
    X[n] = A[n];
    for(int i=n-1; i>=0; i--)
    {
        if( abs(X[i+1] * K) > OO )
        {
            ans = "No";
            return;
        }

        X[i] = X[i+1] * K + A[i];
    }

    if(X[0] != 0)
        ans = "No";
}
//
#define pMax 1000000
bitset <pMax + 1> isPrime;
vi prime;
void sieve(){
    isPrime.set();
    isPrime[0] = isPrime[1] = 0;

    prime.PB(2);
    for(int i=4; i<=pMax; i+=2)
        isPrime[i] = 0;

    for(int i=3; i<=pMax; i+=2)
    {
        if(isPrime[i])
        {
            prime.PB(i);
            if(1LL*i*i > pMax) continue;
            for(int j=i*i; j<=pMax; j+=i)
                isPrime[j] = 0;
        }
    }
}
void check4(string &ans){

    sieve();
    int primeSize = prime.size();
    srand( time(0) );

    for(int itr=0; itr<100; itr++)
    {
        int mod = prime[ rand()%primeSize ];
        DEBUG(mod);
        ll sum = 0, p = 1;
        for(int i=0; i<=n; i++)
        {
            sum += A[i] * p %mod;
            sum %= mod;
            p *= K;
            p %= mod;
        }

        if(sum != 0)
            ans = "No";
    }
}
void check5(string &ans){
    ld sth = 0;
    for(int i=n; i>=0; i--)
    {
        sth = sth * K + A[i];
    }

    if( abs(sth) > EPS )
        ans = "No";
}
//
int main()
{
    read_file();
    FASTIO;
    while(cin>>n>>K)
    {
        done = true;
        humanNow = false;
        games = 0;
        for(int i=0; i<=n; i++)
        {
            string tmp;
            cin>>tmp;
            if(tmp == "?")
            {
                A[i] = OO;
            }
            else
            {
                stringstream(tmp)>>A[i];
                //DEBUG(A[i]);
                games++;
            }
        }

        if(games%2 == 0)
            humanNow = 0;
        else
            humanNow = 1;

        int m = n+1 - games;
        if(m%2 == 0)
            humanLast = !humanNow;
        else
            humanLast = humanNow;

        if(m == 0)
            done = 1;
        else
            done = 0;

        if(done)
        {
            string ans = "Yes";

            if(K == 0)
            {
                if(A[0] != 0)
                    ans = "No";
            }
            else
            {
                check5(ans);
            }

            cout<< ans <<endl;
            continue;
        }

        string ans;
        if(K == 0)
        {
            if(A[0] == 0)
                ans = "Yes";
            else if(A[0] != OO)
                ans = "No";
            else
            {
                if(humanNow)
                    ans = "Yes";
                else
                    ans = "No";
            }
        }
        else
        {
            if(humanLast)
                ans = "Yes";
            else
                ans = "No";
        }

        cout<< ans <<endl;
    }
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697, 99990001, 479001599, 193877777, 6328548, 6679881 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
 	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			for (int i = 0; i < 12; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697, 99990001, 479001599, 193877777, 6328548, 1354828, 16127, 6611, 5795, 26681, 93563 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			for (int i = 0; i < 17; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			if (win && abs(coeffs[n + 1]) % abs(k) == 0)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697, 99990001 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
 	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			for (int i = 0; i < 8; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll BUBEN = (ll)1e12;
ll coeffs[MAXN];
bool bad[MAXN];
ll calc(int n, ll x)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = res * x + coeffs[i];
		if (abs(res) > BUBEN) return BUBEN;
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			if (calc(n + 1, k) != 0)
			{
				win = false;
			}
			if (win && abs(coeffs[n + 1]) % abs(k) == 0)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			for (int i = 0; i < 7; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // man goes, comp wins
			{
				printf("No\n");
			}
			else // comp goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // man goes, man wins
			{
				printf("Yes\n");
			}
			else // comp goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		if (scanf("%lld", &coeffs[i]) != 1)
		{
			bad[i] = true;
		}
	}
	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			for (int i = 0; i < 7; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // man goes, comp wins
			{
				printf("No\n");
			}
			else // comp goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // man goes, man wins
			{
				printf("Yes\n");
			}
			else // comp goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697, 99990001, 479001599, 193877777, 6328548, 1354828 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
 	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			for (int i = 0; i < 12; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
 	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		assert(0);
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			for (int i = 0; i < 7; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697, 99990001, 479001599, 193877777, 6328548, 1354828, 16127, 6611, 5795, 26681, 93563 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			for (int i = 0; i < 17; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697, 99990001, 479001599, 193877777, 6328548, 1354828, 16127, 6611, 5795 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			for (int i = 0; i < 15; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697, 99990001, 479001599, 193877777, 6328548, 1354828, 16127, 6611, 5795, 17, 19, 23, 131071, 953, 31777 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			long double t = 0;
			for (int i = 0; i < 20; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			for (int i = 1; i <= n + 1; i++)
			{
				t = t*k + coeffs[i];
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cstdio>
#include<numeric>
#include<cstring>
#include<ctime>
#include<cstdlib>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<list>
#include<cmath>
#include<bitset>
#include<cassert>
#include<queue>
#include<stack>
#include<deque>
#include<cassert>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 100 * 1000 + 7;
const ll primes[] = { 1000 * 1000 * 1000 + 7, 1000 * 1000 * 1000 + 9, 16769023, 369319, 514229, 433494437, 126247697, 99990001, 479001599, 193877777, 6328548, 1354828, 16127, 6611, 5795, 17, 19, 23, 131071, 953, 31777 };
ll coeffs[MAXN];
bool bad[MAXN];
ll myMod(ll x, ll mod)
{
	if (x >= 0) return x % mod;
	return mod - myMod(-x, mod);
}
ll calc(int n, ll x, ll mod)
{
	ll res = 0;
	for (int i = 1; i <= n; i++)
	{
		res = myMod((res*x + coeffs[i]), mod);
	}
	return res;
}
ll getLL(string s)
{
	int l = 0;
	int mul = 1;
	if (s[l] == '-')
	{
		mul = -1;
		l++;
	}
	ll res = 0;
	for (int i = l; i < (int)s.length(); i++)
	{
		res = 10 * res + s[i] - '0';
	}
	res *= mul;
	return res;
}
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n + 1; i++)
	{
		string s;
		cin >> s;
		if (s == "?")
		{
			bad[i] = true;
		}
		else
		{
			coeffs[i] = getLL(s);
		}
	}
	reverse(coeffs + 1, coeffs + 1 + n + 1);
	reverse(bad + 1, bad + 1 + n + 1);
	int doneSteps = 0;
	for (int i = 1; i <= n + 1; i++)
	{
		if (!bad[i])
		{
			doneSteps++;
		}
	}
	doneSteps %= 2;
	if (k == 0)
	{
		if (bad[n + 1])
		{
			if (doneSteps == 0) // comp goes
			{
				printf("No\n");
			}
			else // man goes
			{
				printf("Yes\n");
			}
		}
		else if (coeffs[n + 1] == 0)
		{
			printf("Yes\n");
		}
		else
		{
			printf("No\n");
		}
	}
	else
	{
		int haveBad = 0;
		for (int i = 1; i <= n + 1; i++)
		{
			if (bad[i]) haveBad++;
		}
		if (haveBad == 0)
		{
			bool win = true;
			long double t = 0;
			for (int i = 0; i < 21; i++)
			{
				if (calc(n + 1, k, primes[i]) != 0)
				{
					win = false;
				}
			}
			for (int i = 1; i <= n + 1; i++)
			{
				t = t*k + coeffs[i];
			}
			if (win)
			{
				printf("Yes\n");
			}
			else
			{
				printf("No\n");
			}
		}
		else if (haveBad % 2 == 1)
		{
			if (doneSteps == 0) // comp goes, comp wins
			{
				printf("No\n");
			}
			else // man goes, man wins
			{
				printf("Yes\n");
			}
		}
		else
		{
			if (doneSteps == 0) // comp goes, man wins
			{
				printf("Yes\n");
			}
			else // man goes, comp wins
			{
				printf("No\n");
			}
		}
	}
}


#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<deque>
#include<iomanip>
#include<sstream>
#include<stack>
#include<iostream>
#include<limits>
#include<bitset>
#include<list>
#include<queue>
#include<memory>
#include<functional>
#include<cstdio>
using namespace std;
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

namespace tree //动态开点
{
	const int N = 4000000;
	const int Q = 4;
	struct node
	{
		node *L, *R;
		int l, r, val;
		void clear()
		{
			L = R = NULL;
			l = r = val = 0;
		}
	};
	node pool[N], *cur;
	void clear()
	{
		cur = pool;
		cur->clear();
	}
	node *new_node(int L, int R, int val)
	{
		cur->l = L, cur->r = R, cur->val = val;
		return cur++;
	}
	void push_down(node *a) //创建合适的子节点
	{
		if ((a->L != NULL && a->R != NULL) || (a->l == a->r))
			return;
		int mid = (a->l + a->r) / 2;
		a->L = new_node(a->l, mid, 0);
		a->R = new_node(mid + 1, a->r, 0);
	}
	void update(node *x)
	{
		if(x->l==x->r) x->val = 1;
		else x->val = 0;
		if (x->L != NULL) x->val += x->L->val;
		if (x->R != NULL) x->val += x->R->val;
	}
	node* insert(node *old_version, int k)//单点插入
	{
		push_down(old_version);
		int l = old_version->l, r = old_version->r;
		node * new_version = new_node(l, r, old_version->val + 1);
		if (l != r)
		{
			int mid = (l + r) / 2;
			if (k >= mid + 1)
			{
				new_version->R = insert(old_version->R, k);
				new_version->L = old_version->L;
			}
			else
			{
				new_version->L = insert(old_version->L, k);
				new_version->R = old_version->R;
			}
		}
		return new_version;
	}
	node *history[Q];
	node *merge(node *x, node *y) //合并x,y,返回合并后的根
	{
		if (x == NULL) return y;
		if (y == NULL) return x;
		node *merge_version = new_node(x->l, x->r, y->val + x->val);
		merge_version->L = merge(x->L, y->L);
		merge_version->R = merge(x->R, y->R);
		return merge_version;
	}
	void merge(int L, int R, node *x, node *y)
	{
		int mid = (x->l + x->r) / 2;
		if (x->l == L && x->r == R)
		{
			if (x->L != NULL && x->L->val != 0) y->L = merge(x->L, y->L);
			if (x->R != NULL && x->R->val != 0) y->R = merge(x->R, y->R);
			x->L = NULL, x->R = NULL;
		}
		else
		{
			push_down(x), push_down(y);
			if (L <= mid && R > mid)
				merge(L, mid, x->L, y->L), merge(mid + 1, R, x->R, y->R);
			else if (R <= mid)
				merge(L, R, x->L, y->L);
			else if (L >= mid + 1)
				merge(L, R, x->R, y->R);
		}
		update(y), update(x);
	}
	void build(int *arr, int n)//建权值线段树,输入离散化后的序列【1-n】,或者值域开够也行，因为已经动态开点了，不过对1e8以上的数据离散化后内存用的少很多
	{
		history[0] = new_node(1, n, 0);
		for (int i = 1; i <= n; ++i)
			history[i] = insert(history[i - 1], arr[i]);
	}
	int query(node *x, int k) //单点查询
	{

		if (x==NULL || x->val == 0 )
			return 0;
		if (x->l == x->r)
			return x->val;
		if (x->L->r >= k)
			return query(x->L, k);
		else
			return query(x->R, k);

	}
	int query_kth(int l, int r, int k)//查询k大
	{
		node * LH = history[l - 1], *RH = history[r];//左右两边的历史版本
		while (RH->r != RH->l)
		{

			int p = RH->L->val - LH->L->val;
			if (k > p)
			{
				k -= p;
				RH = RH->R;
				LH = LH->R;
			}
			else
			{
				RH = RH->L;
				LH = LH->L;
			}

		}
		return RH->r;
	}
}

using namespace tree;
node *segment[150];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	int k;
	clear();
	vector<int> arr(n + 1);
	for (int i = 0; i < 101; ++i)
		segment[i] = new_node(1, 210000, 0);
	for (int i = 1; i <= n; ++i)
	{
		cin >> k;
		segment[k] = insert(segment[k], i);
	}
	int q, l, r, x, y;
	cin >> q;
	while (q--)
	{
		cin >> l >> r >> x >> y;
		merge(l, r, segment[x], segment[y]);
	}
	for (int i = 1; i <= 100; ++i)
	{
		for (int j = 1; j <= n; ++j)
		{
			if (query(segment[i], j) == 1)
				arr[j] = i;
		}
	}
	for (int i = 1; i <= n; ++i)
		cout << arr[i] << " ";
	return 0;
}


#include<string>
#include<cstring>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<deque>
#include<iomanip>
#include<sstream>
#include<stack>
#include<iostream>
#include<limits>
#include<bitset>
#include<list>
#include<queue>
#include<memory>
#include<functional>
#include<cstdio>
using namespace std;
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

namespace tree //动态开点
{
	const int N = 20000000;
	const int Q = 4;
	struct node
	{
		node *L, *R;
		int l, r, val;
		void clear()
		{
			L = R = NULL;
			l = r = val = 0;
		}
	};
	node pool[N], *cur;
	void clear()
	{
		cur = pool;
		cur->clear();
	}
	node *new_node(int L, int R, int val)
	{
		cur->l = L, cur->r = R, cur->val = val;
		return cur++;
	}
	void push_down(node *a) //创建合适的子节点
	{
		if ((a->L != NULL && a->R != NULL) || (a->l == a->r))
			return;
		int mid = (a->l + a->r) / 2;
		a->L = new_node(a->l, mid, 0);
		a->R = new_node(mid + 1, a->r, 0);
	}
	void update(node *x)
	{
		x->val = 0;
		if (x->L != NULL) x->val += x->L->val;
		if (x->R != NULL) x->val += x->R->val;
	}
	node* insert(node *old_version, int k)//单点插入
	{
		push_down(old_version);
		int l = old_version->l, r = old_version->r;
		node * new_version = new_node(l, r, old_version->val + 1);
		if (l != r)
		{
			int mid = (l + r) / 2;
			if (k >= mid + 1)
			{
				new_version->R = insert(old_version->R, k);
				new_version->L = old_version->L;
			}
			else
			{
				new_version->L = insert(old_version->L, k);
				new_version->R = old_version->R;
			}
		}
		return new_version;
	}
	node *history[Q];
	node *merge(node *x, node *y) //合并x,y,返回合并后的根
	{
		if (x == NULL) return y;
		if (y == NULL) return x;
		node *merge_version = new_node(x->l, x->r, y->val + x->val);
		merge_version->L = merge(x->L, y->L);
		merge_version->R = merge(x->R, y->R);
		return merge_version;
	}
	void merge(int L, int R, node *x, node *y)
	{
		if (x == NULL) return;
		int mid = (x->l + x->r) / 2;
		if (x->l == L && x->r == R)
		{
			y->val += x->val;
			y->L = merge(x->L, y->L);
			y->R = merge(x->R, y->R);
			x->L = NULL, x->R = NULL;
		}
		else
		{
			push_down(y);
			if (L <= mid && R > mid)
				merge(L, mid, x->L, y->L), merge(mid + 1, R, x->R, y->R);
			else if (R <= mid)
				merge(L, R, x->L, y->L);
			else if (L >= mid + 1)
				merge(L, R, x->R, y->R);
		}
		update(x);
	}
	void build(int *arr, int n)//建权值线段树,输入离散化后的序列【1-n】,或者值域开够也行，因为已经动态开点了，不过对1e8以上的数据离散化后内存用的少很多
	{
		history[0] = new_node(1, n, 0);
		for (int i = 1; i <= n; ++i)
			history[i] = insert(history[i - 1], arr[i]);
	}

	int query(node *x, int k) //单点查询
	{
		if (x==NULL || x->val == 0 )
			return 0;
		if (x->l == x->r)
			return x->val;
		int mid = (x->l + x->r) / 2;
		if (k >= mid + 1)
			return query(x->R, k);
		else
			return query(x->L, k);
	}
	int query_kth(int l, int r, int k)//查询k大
	{
		node * LH = history[l - 1], *RH = history[r];//左右两边的历史版本
		while (RH->r != RH->l)
		{

			int p = RH->L->val - LH->L->val;
			if (k > p)
			{
				k -= p;
				RH = RH->R;
				LH = LH->R;
			}
			else
			{
				RH = RH->L;
				LH = LH->L;
			}

		}
		return RH->r;
	}
}

using namespace tree;
vector<int> arr;
node *segment[150];
void dfs(node *x,int a)
{
	if (x->L)
		dfs(x->L,a);
	if (x->l == x->r && x->val==1)
		arr[x->l] = a;
	if (x->R)
		dfs(x->R,a);
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n;
	cin >> n;
	int k;
	clear();
	arr.resize(n + 1,0);
	for (int i = 0; i < 101; ++i)
		segment[i] = new_node(1, 210000, 0);
	for (int i = 1; i <= n; ++i)
	{
		cin >> k;
		segment[k] = insert(segment[k], i);
	}
	int q, l, r, x, y;
	cin >> q;
	while (q--)
	{
		cin >> l >> r >> x >> y;
		if(x!=y)
		merge(l, r, segment[x], segment[y]);
	}
	for (int i = 1; i <= 100; ++i)
		dfs(segment[i], i);
	for (int i = 1; i <= n; ++i)
		cout << arr[i] << " ";
	return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 5

short node[MARR][4*MAXN], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int ql, int qr, int l, int r, int x, int y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[i][v]==x) node[i][v]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,4*MAXN) fol(i,0,MARR) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int x, y;
        cin>>u>>v>>x>>y;
        upd(1,u,v,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200001
#define MARR 101

short node[MARR][4*MAXN], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int ql, int qr, int l, int r, int x, int y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[v][i]==x) node[v][i]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,800000) fol(i,0,101) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int x, y;
        cin>>u>>v>>x>>y;
        upd(1,u,v,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

short node[MARR][4*MAXN], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int ql, int qr, int l, int r, int x, int y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[v][i]==x) node[v][i]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,800000) fol(i,0,101) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int x, y;
        cin>>u>>v>>x>>y;
        upd(1,u,v,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

char node[4*MAXN][MARR], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[v<<1][i]=node[v][node[v<<1][i]];
        node[v<<1|1][i]=node[v][node[v<<1|1][i]];
    }
    fol(i,1,MARR) node[v][i]=i;
}

void upd(int v, int ql, int qr, int l, int r, char x, char y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[v][i]==x) node[v][i]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[v][arr[l]];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(i,0,4*MAXN) fol(j,0,MARR) node[i][j]=j;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int l, r, x, y;
        cin>>l>>r>>x>>y;
        upd(1,l,r,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

char node[MARR][3*MAXN], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int &ql, int &qr, int l, int r, int &x, int &y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[i][v]==x) node[i][v]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,3*MAXN) fol(i,0,MARR) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int l, r, x, y;
        cin>>l>>r>>x>>y;
        upd(1,l,r,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

short node[MARR][4*MAXN], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int ql, int qr, int l, int r, int x, int y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[v][i]==x) node[v][i]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,4*MAXN) fol(i,0,MARR) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int x, y;
        cin>>u>>v>>x>>y;
        upd(1,u,v,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

char node[MARR][525000], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int ql, int qr, int l, int r, char x, char y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[i][v]==x) node[i][v]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,525000) fol(i,0,MARR) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int l, r, x, y;
        cin>>l>>r>>x>>y;
        upd(1,l,r,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

char node[MARR][4*MAXN], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int &ql, int &qr, int l, int r, int &x, int &y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[i][v]==x) node[i][v]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,4*MAXN) fol(i,0,MARR) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int l, r, x, y;
        cin>>l>>r>>x>>y;
        upd(1,l,r,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

short node[MARR][4*MAXN], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int ql, int qr, int l, int r, int x, int y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[i][v]==x) node[i][v]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,4*MAXN) fol(i,0,MARR) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int x, y;
        cin>>u>>v>>x>>y;
        upd(1,u,v,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

char node[525000][MARR], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[v<<1][i]=node[v][node[v<<1][i]];
        node[v<<1|1][i]=node[v][node[v<<1|1][i]];
    }
    fol(i,1,MARR) node[v][i]=i;
}

void upd(int v, int ql, int qr, int l, int r, char x, char y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[v][i]==x) node[v][i]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[v][arr[l]];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(i,0,525000) fol(j,0,MARR) node[i][j]=j;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int l, r, x, y;
        cin>>l>>r>>x>>y;
        upd(1,l,r,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}


#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define uid uniform_int_distribution
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define bpop(x) __builtin_popcountll((ulli)x)
#define blead(x) __builtin_clzll((ulli)x)
#define btrail(x) __builtin_ctzll((ulli)x)
const double PI = acos(-1);
template<class my>
using ind_set = tree<my,null_type,less<my>,rb_tree_tag,tree_order_statistics_node_update>;

// primes - 31 53 (1-3)67 1(0-1)87 125(6-8)87 3256(0-9)7
// primes - 569(6-8)09 1299709 2750159 154858(57-63-67) 998244353

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define all(vec) vec.begin(), vec.end()
#define fol(i,a,b) for(int i=a;i<b;i++)
#define loop(i,a,b) for(int i=a;i>=b;i--)
#define forr(x,arr) for(auto& x:arr)
#define mod 1000000007
#define INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-7
#define sz(x) ((lli)(x).size())

using   lli     =   long long;
using   ulli    =   unsigned long long int;
using   pll     =   pair<lli, lli>;
using   ttt     =   pair<lli, pll>;
using   vttt    =   vector<ttt>;
using   vll     =   vector<pll>;
using   vl      =   vector<lli>;
using   vi      =   vector<int>;
using   vvi     =   vector<vector<int>>;
using   cd      =   complex<long double>;

#ifdef tejasp
template<typename T>
void __p(T a) { cout << a << " "; }
template<typename T, typename F>
void __p(pair<T, F> a) { cout << "{ "; __p(a.ff); __p(a.ss); cout << "} "; }
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : ";__p(arg1); cout<<endl;
}
template<typename Arg1>
void __t(const char *name, Arg1 &&arg1)
{ cout<<name<<" : { "; for (auto p : arg1) __p(p); cout<<"}"<<endl; }
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	int bracket=0,i=0;
	for(; ;i++)
		if(names[i]==','&&bracket==0)
			break;
		else if(names[i]=='(')
			bracket++;
		else if(names[i]==')')
			bracket--;
	cout.write(names,i)<<" : ";
	__p(arg1);  cout<<"| ";
	__f(names+i+1,args...);
}
template<typename Arg1, typename Arg2>
void __f(const char *names, Arg1 arg1[], Arg2 &&arg2){
    int i=0;
	for(; ;i++) if(names[i]==',') break;
	cout.write(names,i)<<" : { ";
	fol(i,0,arg2) __p(arg1[i]);
	cout << "} "<<endl;
}
#define trace(...) { cout<<"Line:"<<__LINE__<<" | "; __f(#__VA_ARGS__, __VA_ARGS__); }
#define cotra(...) { cout<<"Line:"<<__LINE__<<" | "; __t(#__VA_ARGS__, __VA_ARGS__); }
#else
#define trace(...) {}
#define cotra(...) {}
#define endl '\n'
#endif

#define MAXN 200002
#define MARR 101

char node[MARR][3*MAXN], arr[MAXN];

void push(int v)
{
    fol(i,1,MARR)
    {
        node[i][v<<1]=node[node[i][v<<1]][v];
        node[i][v<<1|1]=node[node[i][v<<1|1]][v];
    }
    fol(i,1,MARR) node[i][v]=i;
}

void upd(int v, int &ql, int &qr, int l, int r, int &x, int &y)
{
    if(l>qr||r<ql) return;
    if(l>=ql&&r<=qr)
    {
        fol(i,1,MARR) if(node[i][v]==x) node[i][v]=y;
        return;
    }
    int mid=(l+r)/2;
    push(v);
    upd(v<<1,ql,qr,l,mid,x,y);
    upd(v<<1|1,ql,qr,mid+1,r,x,y);
}

void fin(int v, int l, int r)
{
    if(l==r)
    {
        arr[l]=node[arr[l]][v];
        return;
    }
    int mid=(l+r)/2;
    push(v);
    fin(v<<1,l,mid);
    fin(v<<1|1,mid+1,r);
}

int tejas_919(int kkkk)
{
    lli n, m, k, q, u, v, temp=0, ans=0;
    fol(j,0,3*MAXN) fol(i,0,MARR) node[i][j]=i;
    cin>>n;
    fol(i,1,n+1)
    {
        cin>>u;
        arr[i]=u;
    }
    cin>>q;
    while(q--)
    {
        int l, r, x, y;
        cin>>l>>r>>x>>y;
        upd(1,l,r,1,n,x,y);
    }
    fin(1,1,n);
    fol(i,1,n+1)
    {
        u=arr[i];
        cout<<u<<" ";
    }
    cout<<endl;
    return 0;
}

int main()
{
    #ifndef tejasp
        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #endif
    cout << fixed << setprecision(10);
    int t=1;
    //cin>>t;
    fol(i,0,t) { tejas_919(i+1); }
}