using System;
using System.Collections.Generic;
using System.Linq;

public class Program
{
	public static void Main(String[] args)
	{
		var numbers = new List<Int64>();
		Int64 numberOfElements = Convert.ToInt64(Console.ReadLine());
		foreach(String x in Console.ReadLine().Split(' ')) {
			numbers.Add(Convert.ToInt64(x));
		}
		Int64 numOfOperations = Convert.ToInt64(Console.ReadLine());
		for(Int64 i = 0; i < numOfOperations; ++i) {
			String[] x = Console.ReadLine().Split(' ');
			for(int j = 0; j < numbers.Count; ++j) {
				if(numbers[j] == Convert.ToInt64(x[0])) {
					numbers[j] = Convert.ToInt64(x[1]);
				}
			}
			Console.WriteLine(numbers.Sum());
		}
		
	}
}