#include <bits/stdc++.h>
using namespace std;
const long long INF = 2e18;
const long long MOD = 1e9 + 7;
class UnionFind {
  vector<long long> par, rank;

 public:
  void init(long long n) {
    par.resize(n, 1);
    rank.resize(n, 0);
  }
  long long getSize(long long x) { return par[find(x)]; }
  long long find(long long x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(long long x, long long y) { return find(x) == find(y); }
};
long long N;
long long A[100010];
long long B[100010];
map<long long, long long> mp;
int main() {
  cin >> N;
  long long sum = 0;
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
    mp[A[i]]++;
    sum += A[i];
  }
  long long Q;
  cin >> Q;
  for (long long i = 0; i < Q; i++) {
    long long b, c;
    cin >> b >> c;
    sum += mp[b] * (c - b);
    mp[c] += mp[b];
    cout << sum << endl;
  }
  return 0;
}
