#include <bits/stdc++.h>
using namespace std;
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, -1, 0, 1};
int dx8[8] = {1, 0, -1, 1, -1, 1, 0, -1};
int dy8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
int dx9[9] = {0, 1, 0, -1, 1, -1, 1, 0, -1};
int dy9[9] = {0, 1, 1, 1, 0, 0, -1, -1, -1};
const int INF = 1e9;
const long long LLINF = 1e18;
const int MAX_V = 1e6 + 1;
const long long mod = 1000000007;
int n, q;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int x, y;
    cin >> x >> y;
    int t = mp[x];
    mp[x] = 0;
    sum -= x * t;
    sum += y * t;
    mp[y] += t;
    cout << sum << endl;
  }
}
