#include <bits/stdc++.h>
using namespace std;
vector<bool> visited;
vector<vector<int>> graph;
vector<vector<int>> transposedGraph;
vector<int> order;
vector<int> costo;
void dfsVisit(int u) {
  if (!visited[u]) {
    visited[u] = true;
    for (vector<int>::iterator it = graph[u].begin(); it != graph[u].end();
         ++it) {
      int v = *it;
      dfsVisit(v);
      transposedGraph[v].push_back(u);
    }
    order.push_back(u);
  }
}
vector<int> dfsAssign(int u) {
  if (visited[u]) return vector<int>();
  visited[u] = true;
  vector<int> scc;
  scc.push_back(u);
  for (vector<int>::iterator it = transposedGraph[u].begin();
       it != transposedGraph[u].end(); ++it) {
    int v = *it;
    vector<int> partialscc = dfsAssign(v);
    scc.insert(scc.end(), partialscc.begin(), partialscc.end());
  }
  return scc;
}
vector<vector<int>> kosaraju(int n) {
  visited.assign(n, false);
  for (int i = 1; i <= n; i++) {
    dfsVisit(i);
  }
  vector<vector<int>> sccs;
  visited.assign(n, false);
  for (vector<int>::reverse_iterator it = order.rbegin(); it != order.rend();
       ++it) {
    int u = *it;
    vector<int> ans = dfsAssign(u);
    if (!ans.empty()) sccs.push_back(ans);
  }
  return sccs;
}
bool sortear_costo(int a, int b) { return costo[a] < costo[b]; }
int main() {
  int n;
  cin >> n;
  costo.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> costo[i];
  }
  int m;
  cin >> m;
  visited.assign(n + 1, false);
  graph.resize(n + 1);
  transposedGraph.resize(n + 1);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    graph[u].push_back(v);
  }
  auto answer = kosaraju(n);
  long long mincosto = 0;
  long long f = 0;
  long long value = 1;
  for (auto scc : answer) {
    sort(scc.begin(), scc.end(), sortear_costo);
    mincosto += costo[scc[0]];
    f = 0;
    for (auto j : scc) {
      if (costo[scc[0]] == costo[j])
        f++;
      else
        break;
    }
    value = ((value % 1000000007) * (f % 1000000007)) % 1000000007;
  }
  cout << mincosto << " " << value;
  return 0;
}
