#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 17;
const int M = 1 << 19;
const int MOD = 1e9 + 7;
struct Edge {
  int v, nx;
  Edge() {}
  Edge(int v, int nx) : v(v), nx(nx) {}
} edge[M];
int eh[N], ec;
void init(int n = N) {
  memset(eh, -1, sizeof(int) * (n + 2));
  ec = 0;
}
void addedge(int u, int v) {
  edge[ec] = Edge(v, eh[u]);
  eh[u] = ec++;
}
int pre[N], low[N], sccid[N], scccnt, value[N];
int clk, stk[N], top;
vector<int> scc[N];
bool cmp(int a, int b) { return value[a] < value[b]; }
void dfs(int u) {
  pre[u] = low[u] = ++clk;
  stk[++top] = u;
  for (int i = eh[u], v; ~i; i = edge[i].nx) {
    v = edge[i].v;
    if (pre[v]) {
      if (!sccid[v]) low[u] = min(low[u], pre[v]);
    } else {
      dfs(v);
      low[u] = min(low[u], low[v]);
    }
  }
  if (low[u] == pre[u]) {
    scc[++scccnt].clear();
    while (true) {
      scc[scccnt].push_back(stk[top]);
      sccid[stk[top]] = scccnt;
      if (stk[top--] == u) break;
    }
  }
}
void runscc(int n) {
  memset(pre, 0, sizeof(int) * (n + 2));
  memset(low, 0, sizeof(int) * (n + 2));
  memset(sccid, 0, sizeof(int) * (n + 2));
  scccnt = clk = 0, top = -1;
  for (int i = 1; i <= n; i++)
    if (!sccid[i]) dfs(i);
}
int run() {
  int n, m;
  while (cin >> n) {
    init();
    for (int i = 1; i <= n; ++i) {
      cin >> value[i];
    }
    cin >> m;
    int x, y;
    for (int i = 0; i < m; ++i) {
      cin >> x >> y;
      addedge(x, y);
    }
    runscc(n);
    long long ans1 = 0, ans2 = 1;
    for (int i = 1; i <= scccnt; ++i) {
      sort(scc[i].begin(), scc[i].end(), cmp);
      ans1 += value[scc[i][0]];
      int c = 0;
      while (c < scc[i].size() && value[scc[i][c]] == value[scc[i][0]]) ++c;
      ans2 *= c;
      ans2 %= MOD;
    }
    cout << ans1 << ' ' << ans2 << endl;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  return run();
}
