#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
vector<int> adjlist[N], s;
int n, m, id = 0, dfs_num[N], dfs_low[N], w[N], visit[N], v;
long long sum = 1, cost = 0;
void tarjanscc(int u) {
  visit[u] = 1;
  s.push_back(u);
  dfs_low[u] = dfs_num[u] = id++;
  for (int i = 0; i < adjlist[u].size(); i++) {
    int v = adjlist[u][i];
    if (visit[v] == -1) tarjanscc(v);
    if (visit[v]) dfs_low[u] = min(dfs_low[u], dfs_low[v]);
  }
  if (dfs_num[u] == dfs_low[u]) {
    int tmp = INT_MAX, cnt = 0;
    while (1) {
      v = s.back();
      if (tmp > w[v]) {
        cnt = 1;
        tmp = w[v];
      } else if (tmp == w[v])
        cnt++;
      s.pop_back();
      visit[v] = 0;
      if (u == v) break;
    }
    cost += tmp;
    sum = (sum * cnt) % mod;
  }
}
int main() {
  cin >> n;
  int i, x, y;
  for (i = 1; i <= n; i++) {
    cin >> w[i];
    visit[i] = -1;
  }
  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> x >> y;
    adjlist[x].push_back(y);
  }
  for (i = 1; i <= n; i++) {
    if (visit[i] == -1) tarjanscc(i);
  }
  cout << cost << " " << sum << endl;
}
