#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(const char &ch) { return "'" + string(1, ch) + "'"; }
string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}
template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  reverse(res.begin(), res.end());
  return res;
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "{" + to_string(p.first) + ", " + to_string(p.second) + "}";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "{" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + "}";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "{" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
class segtree {
 public:
  struct node {
    int val = 0;
    int sum = 0;
    bool mark = false;
    bool leaf = false;
    void apply(int l, int h, int v) {
      val = v;
      sum = (h - l + 1) * v;
      mark = true;
    }
  };
  node unite(const node &a, const node &b) const {
    node res;
    res.val = a.val;
    res.sum = a.sum + b.sum;
    return res;
  }
  inline void push(int i, int l, int h) {
    int m = (l + h) >> 1;
    if (tree[i].mark) {
      tree[i << 1].apply(l, m, tree[i].val);
      tree[(i << 1) + 1].apply(m + 1, h, tree[i].val);
      tree[i].val = 0;
      tree[i].mark = false;
    }
  }
  inline void pull(int i) { tree[i] = unite(tree[i << 1], tree[(i << 1) + 1]); }
  int n;
  vector<node> tree;
  void build(int i, int l, int h) {
    if (l == h) {
      tree[i].leaf = true;
      return;
    }
    int m = (l + h) >> 1;
    build(i << 1, l, m);
    build((i << 1) + 1, m + 1, h);
    pull(i);
  }
  template <typename M>
  void build(int i, int l, int h, const vector<M> &v) {
    if (l == h) {
      tree[i].apply(l, h, v[l]);
      tree[i].leaf = true;
      return;
    }
    int m = (l + h) >> 1;
    build(i << 1, l, m, v);
    build((i << 1) + 1, m + 1, h, v);
    pull(i);
  }
  node get(int i, int l, int h, int ql, int qh) {
    if (ql <= l && h <= qh) {
      return tree[i];
    }
    int m = (l + h) >> 1;
    push(i, l, h);
    node res{};
    if (qh <= m) {
      res = get(i << 1, l, m, ql, qh);
    } else {
      if (ql > m) {
        res = get((i << 1) + 1, m + 1, h, ql, qh);
      } else {
        res = unite(get(i << 1, l, m, ql, qh),
                    get((i << 1) + 1, m + 1, h, ql, qh));
      }
    }
    pull(i);
    return res;
  }
  template <typename... M>
  void modify(int i, int l, int h, int ql, int qh, const M &...v) {
    if (ql <= l && h <= qh) {
      tree[i].apply(l, h, v...);
      return;
    }
    int m = (l + h) >> 1;
    push(i, l, h);
    if (ql <= m) {
      modify(i << 1, l, m, ql, qh, v...);
    }
    if (qh > m) {
      modify((i << 1) + 1, m + 1, h, ql, qh, v...);
    }
    pull(i);
  }
  int find_first_knowingly(int i, int l, int h,
                           const function<bool(const node &)> &f) {
    if (l == h) {
      return l;
    }
    push(i, l, h);
    int m = (l + h) >> 1;
    int res;
    if (f(tree[i << 1])) {
      res = find_first_knowingly(i << 1, l, m, f);
    } else {
      res = find_first_knowingly((i << 1) + 1, m + 1, h, f);
    }
    pull(i);
    return res;
  }
  int find_first(int i, int l, int h, int ql, int qh,
                 const function<bool(const node &)> &f) {
    if (ql <= l && h <= qh) {
      if (!f(tree[i])) {
        return -1;
      }
      return find_first_knowingly(i, l, h, f);
    }
    push(i, l, h);
    int m = (l + h) >> 1;
    int res = -1;
    if (ql <= m) {
      res = find_first(i << 1, l, m, ql, qh, f);
    }
    if (qh > m && res == -1) {
      res = find_first((i << 1) + 1, m + 1, h, ql, qh, f);
    }
    pull(i);
    return res;
  }
  int find_last_knowingly(int i, int l, int h,
                          const function<bool(const node &)> &f) {
    if (l == h) {
      return l;
    }
    push(i, l, h);
    int m = (l + h) >> 1;
    int res;
    if (f(tree[(i << 1) + 1])) {
      res = find_last_knowingly((i << 1) + 1, m + 1, h, f);
    } else {
      res = find_last_knowingly(i << 1, l, m, f);
    }
    pull(i);
    return res;
  }
  int find_last(int i, int l, int h, int ql, int qh,
                const function<bool(const node &)> &f) {
    if (ql <= l && h <= qh) {
      if (!f(tree[i])) {
        return -1;
      }
      return find_last_knowingly(i, l, h, f);
    }
    push(i, l, h);
    int m = (l + h) >> 1;
    int res = -1;
    if (qh > m) {
      res = find_last((i << 1) + 1, m + 1, h, ql, qh, f);
    }
    if (ql <= m && res == -1) {
      res = find_last(i << 1, l, m, ql, qh, f);
    }
    pull(i);
    return res;
  }
  segtree(int _n) : n(_n) {
    assert(n > 0);
    tree.resize(4 * n);
    build(1, 0, n - 1);
  }
  template <typename M>
  segtree(const vector<M> &v) {
    n = (int)v.size();
    assert(n > 0);
    tree.resize(4 * n);
    build(1, 0, n - 1, v);
  }
  node get(int ql, int qh) {
    assert(0 <= ql && ql <= qh && qh <= n - 1);
    return get(1, 0, n - 1, ql, qh);
  }
  node get(int p) {
    assert(0 <= p && p <= n - 1);
    return get(1, 0, n - 1, p, p);
  }
  template <typename... M>
  void modify(int ql, int qh, const M &...v) {
    assert(0 <= ql && ql <= qh && qh <= n - 1);
    modify(1, 0, n - 1, ql, qh, v...);
  }
  int find_first(int ql, int qh, const function<bool(const node &)> &f) {
    assert(0 <= ql && ql <= qh && qh <= n - 1);
    return find_first(1, 0, n - 1, ql, qh, f);
  }
  int find_last(int ql, int qh, const function<bool(const node &)> &f) {
    assert(0 <= ql && ql <= qh && qh <= n - 1);
    return find_last(1, 0, n - 1, ql, qh, f);
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  map<int, vector<pair<int, int> > > mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  int h = 0;
  while (h < n) {
    int l = h;
    while (h + 1 < n && arr[h + 1] == arr[l]) {
      h++;
    }
    mp[arr[l]].push_back(make_pair(l, h));
    h++;
  }
  segtree st(arr);
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    auto it = mp.find(b);
    if (it != mp.end()) {
      vector<pair<int, int> > temp = it->second;
      for (pair<int, int> &pr : temp) {
        int L = pr.first;
        int H = pr.second;
        st.modify(L, H, c);
      }
      mp.erase(it);
      auto prev = mp.find(c);
      if (prev != mp.end()) {
        for (pair<int, int> pr : temp) {
          prev->second.push_back(pr);
        }
      } else {
        mp[c] = temp;
      }
    }
    auto ans = st.get(0, n - 1);
    cout << ans.sum << '\n';
  }
  return 0;
}
