using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

namespace AtCoderCs {
    class Program {
        static void Main(string[] args) {
            long N = long.Parse(ReadLine());
            List<long> A = ReadLine().Split(' ').Select(long.Parse).ToList();
            long Q = long.Parse(ReadLine());

            long sum = 0;
            foreach(var e in A) {
                sum += e;
            }
            var l = A.GroupBy(e => e).Select(x => new cv(x.Key, x.Count())).ToList();

            List<long> anses = new List<long>();

            for(int i = 0;i < Q;i++) {
                var t = ReadLine().Split(' ').Select(long.Parse).ToArray();
                long B = t[0];
                long C = t[1];

                long diff = C - B;
                var c = l.Find(x => x.v == B);
                if(c == null) {
                    goto Label;
                }

                l.Remove(c);

                sum += c.c * diff;
                var d = l.Find(x => x.v == C);
                if(d == null) {
                    l.Add(new cv(C, c.c));
                } else {
                    d.c += c.c;
                }

                Label:;
                anses.Add(sum);
            }

            foreach(var e in anses) {
                WriteLine(e);
            }

            ReadLine();
        }
    }
    class cv {
        public long v, c;
        public cv(long v, long c) {
            this.v = v;
            this.c = c;
        }
    }
}
