#include <bits/stdc++.h>
using namespace std;
vector<long long int> Price;
vector<vector<int> > G;
vector<vector<int> > GT;
vector<int> Top_Order;
vector<int> Visited;
vector<int> Component;
long long MOD = pow(10, 9) + 7;
void DFS1(int v) {
  Visited[v] = true;
  for (int x : G[v]) {
    if (!Visited[x]) {
      DFS1(x);
    }
  }
  Top_Order.push_back(v);
}
void DFS2(int v, int c) {
  Component[v] = c;
  for (int x : GT[v]) {
    if (Component[x] == -1) {
      DFS2(x, c);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n;
  Price.resize(n + 1);
  G.resize(n + 1);
  GT.resize(n + 1);
  Visited.resize(n + 1, false);
  Component.resize(n + 1, -1);
  for (int i = 1; i <= n; i++) {
    cin >> Price[i];
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    G[a].push_back(b);
    GT[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (!Visited[i]) {
      DFS1(i);
    }
  }
  reverse(Top_Order.begin(), Top_Order.end());
  int c = 1;
  for (int v : Top_Order) {
    if (Component[v] == -1) {
      DFS2(v, c);
      c++;
    }
  }
  vector<vector<int> > SCC(c + 1);
  for (int i = 1; i <= n; i++) {
    int curr = Component[i];
    SCC[curr].push_back(i);
  }
  long long int price = 0;
  vector<int> No;
  int curr = -1;
  for (auto V : SCC) {
    if (V.size() != 0) {
      long long int minimum = LLONG_MAX;
      No.push_back(0);
      curr++;
      for (int x : V) {
        minimum = min(minimum, Price[x]);
      }
      price += minimum;
      for (int x : V) {
        if (Price[x] == minimum) {
          No[curr]++;
        }
      }
    }
  }
  cout << price << " ";
  long long int prod = 1;
  for (int i = 0; i < No.size(); i++) {
    prod *= No[i];
    prod %= MOD;
  }
  cout << prod;
  return 0;
}
