#include <bits/stdc++.h>
using namespace std;
long long t, n, m, u, v, vis[100001], c[100001], i, cn, ans, mod = 1E9 + 7;
vector<long long> graph[100001], adj[100001];
stack<long long> s;
map<long long, long long> cnt;
void dfs(long long x) {
  vis[x] = 1;
  for (auto i : graph[x])
    if (!vis[i]) dfs(i);
  s.push(x);
}
void sfd(long long x) {
  vis[x] = 1, cnt[c[x]]++, t = min(t, c[x]);
  for (auto i : adj[x])
    if (!vis[i]) sfd(i);
}
int main() {
  cin >> n, ans = 1;
  for (i = 1; i <= n; i++) cin >> c[i];
  cin >> m;
  for (i = 0; i < m; i++)
    cin >> u >> v, graph[u].push_back(v), adj[v].push_back(u);
  for (i = 1; i <= n; i++)
    if (!vis[i]) dfs(i);
  for (i = 1; i <= n; i++) vis[i] = 0;
  while (!s.empty()) {
    if (!vis[s.top()])
      t = 1E9 + 1, cnt.clear(), sfd(s.top()), cn += t, ans *= cnt[t];
    s.pop();
  }
  cout << cn << ' ' << ans % mod;
  return 0;
}
