#include <bits/stdc++.h>
using namespace std;
void dfsTopo(int v, vector<vector<int>> &g, vector<bool> &used,
             vector<int> &tSort) {
  used[v] = true;
  for (int to : g[v])
    if (!used[to]) dfsTopo(to, g, used, tSort);
  tSort.push_back(v);
}
void dfs(int v, vector<vector<int>> &g, vector<bool> &used, vector<int> &comp) {
  used[v] = true;
  comp.push_back(v);
  for (int to : g[v])
    if (!used[to]) dfs(to, g, used, comp);
}
void solve1() {
  int n, m;
  cin >> n;
  vector<int> vert(n, 0);
  for (int i = 0; i < n; i++) cin >> vert[i];
  vector<vector<int>> g(n, vector<int>());
  vector<vector<int>> gT(n, vector<int>());
  cin >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    gT[v].push_back(u);
  }
  vector<bool> used(n, false);
  vector<int> tSort;
  for (int i = 0; i < n; i++)
    if (!used[i]) dfsTopo(i, g, used, tSort);
  used.assign(used.size(), false);
  vector<vector<int>> comps;
  for (vector<int>::reverse_iterator rit = tSort.rbegin(); rit != tSort.rend();
       rit++)
    if (!used[*rit]) {
      comps.push_back(vector<int>());
      dfs(*rit, gT, used, comps.back());
    }
  long long sum = 0, count = 1;
  for (vector<int> comp : comps) {
    int min = INT_MAX, countMin = 0;
    for (int v : comp)
      if (vert[v] < min) {
        min = vert[v];
        countMin = 1;
      } else if (vert[v] == min)
        countMin++;
    sum += min;
    count *= countMin;
  }
  cout << sum << " " << count % 1000000007 << endl;
}
int main() {
  solve1();
  return 0;
}
