#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> G[100000];
vector<long long> G2[100000];
long long edge[300000][2];
int visited[100000] = {0};
long long cost[100000];
vector<long long> S;
void dfs(long long v, pair<long long, long long> &cmin, bool c = false) {
  visited[v] = 1;
  if (cmin.first > cost[v])
    cmin = make_pair(cost[v], 1);
  else if (cmin.first == cost[v])
    cmin.second++;
  for (auto it : G[v])
    if (visited[it] == 0) dfs(it, cmin, c);
  if (!c) S.emplace_back(v);
}
pair<long long, long long> kosaraju() {
  pair<long long, long long> res;
  long long scc = 1;
  for (long long i = 0; i < n; i++)
    if (visited[i] == 0) {
      res = make_pair(cost[i], 0);
      dfs(i, res);
    }
  swap(G, G2);
  for (long long i = 0; i < m; i++) {
    swap(edge[i][0], edge[i][1]);
    G[edge[i][0]].emplace_back(edge[i][1]);
  }
  fill(visited, visited + n, 0);
  long long total = 0;
  for (long long i = n - 1; i >= 0; i--)
    if (visited[S[i]] == 0) {
      res = make_pair(cost[S[i]], 0);
      dfs(S[i], res, true);
      scc = (scc * res.second) % 1000000007;
      total += res.first;
    }
  return make_pair(total, scc);
}
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> cost[i];
  cin >> m;
  for (long long i = 0; i < m; i++) {
    cin >> edge[i][0] >> edge[i][1];
    G[--edge[i][0]].emplace_back(--edge[i][1]);
  }
  pair<long long, long long> ans = kosaraju();
  cout << ans.first << " " << ans.second << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  for (long long i = 0; i < t; i++) solve();
}
