#include <bits/stdc++.h>
using namespace std;
struct graph {
  int n;
  vector<vector<int>> adj;
  graph(int n) : n(n), adj(n) {}
  void add_edge(int u, int v) { adj[u].push_back(v); }
  vector<int> &operator[](int u) { return adj[u]; }
};
vector<vector<int>> scc_gabow(graph &adj) {
  int n = adj.n;
  vector<vector<int>> scc;
  vector<int> S, B, I(n);
  function<void(int)> dfs = [&](int u) {
    B.push_back(I[u] = S.size());
    S.push_back(u);
    for (int v : adj[u])
      if (!I[v])
        dfs(v);
      else
        while (I[v] < B.back()) B.pop_back();
    if (I[u] == B.back()) {
      scc.push_back({});
      for (B.pop_back(); I[u] < S.size(); S.pop_back()) {
        scc.back().push_back(S.back());
        I[S.back()] = n + scc.size();
      }
    }
  };
  for (int u = 0; u < n; ++u)
    if (!I[u]) dfs(u);
  return scc;
}
const long long mod = 1000000007;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  graph adj(n);
  int m;
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    adj.add_edge(--u, --v);
  }
  auto scc = scc_gabow(adj);
  long long mn = 0, ways = 1;
  for (auto &comp : scc) {
    long long best = a[comp[0]], total = 0;
    for (int u : comp)
      if (a[u] == best)
        ++total;
      else if (a[u] < best)
        best = a[u], total = 1;
    mn += best;
    ways = ways * total % mod;
  }
  cout << mn << " " << ways << '\n';
  return 0;
}
