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 q = int.Parse(Console.ReadLine());
		for (int i = 0; i < q; i++)
		{
			var v = Read();
			a = a.Where(x => x == v[0]).Select(x => v[1]).Concat(a.Where(x => x != v[0])).ToArray();
			Console.WriteLine(a.Sum());
		}
	}
}