using System;
using System.Linq;

class D
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		Console.ReadLine();
		var a = Read();
		var s = new int[100001];
		var ans = 0;
		for (int i = 0; i < a.Length; i++)
		{
			s[a[i]]++;
			ans += a[i] * 1;
		}
		var q = int.Parse(Console.ReadLine());
		for (int j = 0; j < q; j++)
		{
			var v = Read();
			if (s[v[0]] > 0)
			{
				s[v[1]] += s[v[0]];
				ans += s[v[0]] * (v[1] - v[0]);
				s[v[0]] = 0;	
			}
			Console.WriteLine(ans);
		}
	}
}