Under construction

Still being built. Things may change

Car Workshops

Interview

Time limit1sMemory limit512 MB

Summary
Cars pass through workshops in order and each one repaints color a to b on a match, so compute every final color.
Level

Medium5 of 10

Topics
Simulation, Array
Solved
No attempts yet

Problem

In Byteland (Bajtocja) there is only one road connecting the east with the west. It passes through exactly mm cities, and in each of them there is a car workshop that can repaint a car. Every workshop runs a promotion under which it repaints a car of color aja_j into color bjb_j for free (here jj is the number of the city along the road, j=1,2,…,mj = 1, 2, \dots, m). Each workshop chooses these two colors independently, and every workshop has exactly one such promotion.

A convoy of nn cars set off from the east toward the west. The drivers in Byteland are very frugal, but they also like to freshen up their cars. For this reason every driver tries to repaint their car in each successive city, but does so only when it is free. In other words, at a given workshop a car is changed to color bjb_j only if its current color is exactly aja_j.

Knowing the initial colors of all the cars, determine their colors after they reach the west. Assume the road is one-way, that is, the cars move only from east to west.

Input

The first line contains three integers nn, mm, and kk (1≤n,m,k≤1 000 0001 \le n, m, k \le 1\,000\,000) separated by single spaces, denoting respectively the number of cars, the number of cities, and the number of possible car colors. The colors are numbered from 11 to kk.

The second line contains nn integers kik_i (1≤ki≤k1 \le k_i \le k) separated by single spaces, denoting the initial colors of the successive cars.

Each of the next mm lines describes the workshops visited in order along the route. Each such description consists of two integers aja_j and bjb_j (1≤aj,bj≤k1 \le a_j, b_j \le k) separated by a single space, meaning that the workshop in the jj-th city repaints a car of color aja_j into color bjb_j for free.

Output

In the first and only line print nn integers, separated by single spaces, denoting the colors of the successive cars after they reach the west.

Hint

Walkthrough of the sample. At the first workshop the second and fifth cars (color 22) are repainted, so the sequence of colors becomes 1 4 3 4 4. At the second workshop only the first car (color 11) changes, giving 2 4 3 4 4. Finally, at the third workshop the second, fourth, and fifth cars (color 44) are repainted, so the final sequence of colors is 2 1 3 1 1.

Examples8

  1. Example 1

    Input
    5 3 4
    1 2 3 4 2
    2 4
    1 2
    4 1
    
    Expected output
    2 1 3 1 1
    
  2. Example 2

    Input
    1 1 1
    1
    1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    3 3 5
    1 2 3
    1 4
    2 5
    3 1
    
    Expected output
    4 5 1
    
  4. Example 4

    Input
    4 3 3
    1 2 1 3
    1 2
    3 1
    2 1
    
    Expected output
    1 1 1 1
    
  5. Example 5

    Input
    5 1 2
    2 2 2 2 2
    2 1
    
    Expected output
    1 1 1 1 1
    
  6. Example 6

    Input
    3 3 10
    5 5 6
    1 2
    3 4
    7 8
    
    Expected output
    5 5 6
    
  7. Example 7

    Input
    2 2 2
    1 2
    1 2
    2 1
    
    Expected output
    1 1
    
  8. Example 8

    Input
    6 4 4
    1 1 2 2 3 4
    1 3
    2 3
    4 3
    3 2
    
    Expected output
    2 2 2 2 2 2