#include <bits/stdc++.h>
using namespace std;
const int MAXN = 222222;
const int inf = 1e9 + 7;
vector<int> adj[MAXN], radj[MAXN];
int vis[MAXN], q[MAXN], qn, C;
int cost[MAXN], mn[MAXN], cnt[MAXN];
void dfs(int u) {
  vis[u] = 1;
  for (auto v : adj[u]) {
    if (vis[v] == 1) continue;
    dfs(v);
  }
  q[qn++] = u;
}
void rdfs(int u) {
  vis[u] = C;
  for (int i = 0; i < radj[u].size(); i++) {
    int v = radj[u][i];
    if (vis[v] == 0) rdfs(v);
  }
}
void SCC(int n) {
  for (int i = 1; i <= n; i++) vis[i] = 0;
  qn = C = 0;
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) {
      dfs(i);
    }
  }
  for (int i = 1; i <= n; i++) vis[i] = 0;
  for (int i = qn - 1; i >= 0; i--) {
    int cc = q[i];
    if (!vis[cc]) {
      C++;
      rdfs(cc);
    }
  }
}
int main() {
  int n, m, u, v;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", cost + i);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    adj[u].push_back(v);
    radj[v].push_back(u);
  }
  SCC(n);
  for (int i = 1; i <= C; i++) {
    mn[i] = inf;
    cnt[i] = 0;
  }
  for (int i = 1; i <= n; i++) {
    int cc = vis[i];
    if (mn[cc] == cost[i]) cnt[cc]++;
    if (mn[cc] > cost[i]) mn[cc] = cost[i], cnt[cc] = 1;
  }
  long long ansc = 0, ansn = 1;
  for (int i = 1; i <= C; i++) {
    ansc += mn[i];
    ansn = (1LL * ansn * cnt[i]) % inf;
  }
  printf("%lld %lld\n", ansc, ansn);
  return 0;
}
