#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
vector<vector<int> > graph;
vector<vector<int> > rgraph;
vector<pair<int, int> > comp;
vector<bool> used;
stack<int> sorted;
vector<int> price;
void clear_used() {
  for (size_t i = 0; i < used.size(); i++) used[i] = false;
}
bool dfs_comp(int v, int c) {
  if (used[v]) return false;
  used[v] = true;
  if (price[v] < comp[c].first) {
    comp[c] = {price[v], 1};
  } else if (price[v] == comp[c].first) {
    comp[c].second++;
  }
  for (int u : rgraph[v]) {
    dfs_comp(u, c);
  }
  return true;
}
void dfs_sort(int v) {
  if (used[v]) return;
  used[v] = true;
  for (int u : graph[v]) {
    dfs_sort(u);
  }
  sorted.push(v);
}
int main() {
  int n;
  cin >> n;
  graph.resize(n);
  rgraph.resize(n);
  used.resize(n);
  price.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &price[i]);
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    graph[a].push_back(b);
    rgraph[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    dfs_sort(i);
  }
  clear_used();
  int i = 0;
  comp.push_back({MOD, 0});
  while (!sorted.empty()) {
    if (dfs_comp(sorted.top(), i)) {
      i++;
      comp.push_back({MOD, 0});
    }
    sorted.pop();
  }
  comp.pop_back();
  long long pr = 0;
  int var = 1;
  for (auto p : comp) {
    pr += p.first;
    var = (long long)var * p.second % MOD;
  }
  cout << pr << ' ' << var << endl;
}
