#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
const int mod = 1e9 + 7;
const int INF = 1e9;
vector<int> G[maxn + 5], G2[maxn + 5];
vector<int> s;
int n, m, u, v, cur;
long long ans1 = 0, ans2 = 1;
int min1[maxn + 5], cnt[maxn + 5], a[maxn + 5], cc[maxn + 5];
bool vis[maxn + 5];
void dfs1(int u) {
  vis[u] = true;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    if (!vis[v]) dfs1(v);
  }
  s.push_back(u);
}
void dfs2(int u) {
  cc[u] = cur;
  if (a[u] < min1[cur]) {
    min1[cur] = a[u];
    cnt[cur] = 1;
  } else if (a[u] == min1[cur]) {
    cnt[cur]++;
  }
  for (int i = 0; i < G2[u].size(); i++) {
    int v = G2[u][i];
    if (!cc[v]) dfs2(v);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G2[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) min1[i] = INF;
  for (int i = 1; i <= n; i++)
    if (!vis[i]) dfs1(i);
  for (int i = n - 1; i >= 0; i--)
    if (!cc[s[i]]) {
      cur++;
      dfs2(s[i]);
    }
  for (int i = 1; i <= cur; i++) {
    ans1 += min1[i];
    ans2 = ans2 * cnt[i] % mod;
  }
  printf("%lld %lld\n", ans1, ans2);
  return 0;
}
