#include <bits/stdc++.h>
using namespace std;
vector<int> v[110000], u[110000];
stack<int> s;
int cost[110000], n, m, nod, x, y, viz[110000], tc, key, best, nrb;
long long sol, cst;
void dfs(int x) {
  viz[x] = tc;
  for (int i = 0; i < v[x].size(); ++i)
    if (!viz[v[x][i]]) dfs(v[x][i]);
  s.push(x);
}
void df(int x, int key) {
  viz[x] = 0;
  if (cost[x] < best) {
    best = cost[x];
    nrb = 1;
  } else if (cost[x] == best)
    nrb++;
  for (int i = 0; i < u[x].size(); ++i)
    if (viz[u[x][i]] == key) df(u[x][i], key);
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> cost[i];
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> x >> y;
    v[x].push_back(y);
    u[y].push_back(x);
  }
  for (int i = 1; i <= n; ++i) {
    if (!viz[i]) {
      ++tc;
      dfs(i);
    }
  }
  tc = 0;
  sol = 1;
  while (!s.empty()) {
    while (!s.empty() && !viz[s.top()]) s.pop();
    if (s.empty()) break;
    nod = s.top();
    s.pop();
    key = viz[nod];
    ++tc;
    best = (1 << 30);
    nrb = 0;
    df(nod, key);
    sol = sol * nrb % 1000000007;
    cst += best;
  }
  cout << cst << " " << sol;
  return 0;
}
