#include <cstdio>
#include <vector>
#include <memory.h>
using namespace std;
const char iname[] = "gather.in";
const char oname[] = "gather.out";
#define MAXK 16
#define MAXSTATE 1 << MAXK
#define MAXN 755
#define INF 4294967295
#define swap(a, b) ((a) ^= (b) ^= (a) ^= (b))
typedef unsigned int uint;
int K, N, M;
uint C[MAXSTATE][MAXK]; int P[MAXK + 1];
struct tlist_node {
int nod;
uint cst, cap;
void update(int nod, uint cst, uint cap) {
this->nod = nod;
this->cst = cst;
this->cap = cap;
}
} ;
vector <tlist_node> G[MAXN];
uint dist[MAXK][MAXK], D[MAXN]; int Q[MAXN];
void BellmanFord(int k, int s, uint cnt)
{
int h, t;
vector <tlist_node>::iterator it;
for (int i = 1; i <= N; ++ i)
D[i] = INF;
D[s] = 0;
for (Q[h = t = 0] = s; h <= t; ++ h)
{
int x = Q[h];
for (it = G[x].begin(); it != G[x].end(); ++ it) if (it->cap >= cnt)
if (D[it->nod] > D[x] + it->cst) {
D[it->nod] = D[x] + it->cst;
Q[++ t] = it->nod;
}
}
for (int i = 0; i < K; ++ i)
dist[k][i] = D[P[i]];
}
uint g(int s, int p)
{
if (C[s][p] != -1) return C[s][p];
if (s & (s - 1))
{ // sunt cel putin doi detinuti
int cnt = 0;
for (int i = 0; i < K; ++ i) if ((s >> i) & 1)
cnt ++;
int t = s ^ (1 << p);
for (int i = 0; i < K; ++ i) if ((t >> i) & 1)
{
uint res = g(t, i) + cnt * dist[i][p];
if (C[s][p] == -1 || C[s][p] > res)
C[s][p] = res;
}
} else
C[s][p] = dist[K][p];
return C[s][p];
}
void f(int s, int k, int n)
{
if (n == 0) {
for (int i = 0; i < K; ++ i) if ((s >> i) & 1)
g(s, i);
} else {
if (K - k > n)
f(s, k + 1, n);
f(s | (1 << k), k + 1, n - 1);
}
}
int main(void)
{
freopen(iname, "r", stdin);
freopen(oname, "w", stdout);
int x, y, cst, cap;
scanf("%d %d %d", &K, &N, &M);
for (int i = 0; i < K; ++ i)
scanf("%d", &P[i]);
tlist_node t;
for (int i = 0; i < M; ++ i) {
scanf("%d %d %u %u", &x, &y, &cst, &cap);
t.update(y, cst, cap);
G[x].push_back(t);
t.update(x, cst, cap);
G[y].push_back(t);
}
memset(C, -1, sizeof(C));
P[K] = 1;
for (int k = 1; k <= K; ++ k) {
for (int i = 0; i <= K; ++ i)
BellmanFord(i, P[i], k - 1);
f(0, 0, k);
}
uint ans = -1;
for (int i = 0; i < K; ++ i) {
if (ans == -1 || ans > C[(1 << K) - 1][i])
ans = C[(1 << K) - 1][i];
}
printf("%u\n", ans);
return 0;
}