#include <bits/stdc++.h>
using namespace std;
ifstream fin("gather.in");
ofstream fout("gather.out");
const int NMAX = 760;
struct coridor
{
int ending;
int lungime, capacitate;
};
vector<coridor> graf[NMAX];
int k, n, m;
long long dp[NMAX][1<<18]; //[coridor][folositi]
int dpBiti[1<<18];
long long res = INT_MAX;
int nodes[NMAX];
//nefolosit = 0, folosit = 1
bool checkIfUsed(int node, int used)
{
int place = nodes[node]-1;
if(place==-1) return false;
if((used^(1<<(place)))<used) return false;
return true;
}
bool secondCheck(int node, int used)
{
if((used^node)<used) return true;
return false;
}
int addUsed(int node, int used)
{
int place = nodes[node]-1;
used+=(1<<(place));
return used;
}
int countBits(int i)
{
i = i - ((i >> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >> 2) & 0x33333333);
return (((i + (i >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
}
struct CustomCompare
{
bool operator()(pair<int, int> a, pair<int, int> b)
{
return dp[a.first][a.second]<dp[b.first][b.second];
}
};
priority_queue<pair<int, int>,vector<pair<int,int>>, CustomCompare> cue;
bool inStack [NMAX][1<<18];
void calc()
{
inStack[1][0] = true;
while(cue.size()){
int node = cue.top().first, used = cue.top().second;
if(checkIfUsed(node, used) && countBits(used)==k-1)
res = min(res, dp[node][used]);
for(coridor cor: graf[node])
{
if(cor.capacitate>=countBits(used))
{
if(cor.capacitate>=countBits(used)+1){
if(checkIfUsed(node, used))
{
if(dp[cor.ending][addUsed(node, used)]>(long long)dp[node][used]+(long long)cor.lungime*(countBits(used)+2))
{
if(!inStack[cor.ending][addUsed(node, used)]);
cue.push({cor.ending,addUsed(node, used)});
inStack[cor.ending][addUsed(node, used)] = true;
dp[cor.ending][addUsed(node, used)] = (long long)dp[node][used]+(long long)cor.lungime*(countBits(used)+2);
}
}
}
if(dp[cor.ending][used]>(long long)dp[node][used]+cor.lungime*(countBits(used)+1))
{
if(!inStack[cor.ending][used])
cue.push({cor.ending,used});
inStack[cor.ending][used] = true;
dp[cor.ending][used] = (long long)dp[node][used]+(long long)cor.lungime*(countBits(used)+1);
}
}
}
inStack[cue.top().first][cue.top().second] = false;
cue.pop();
}
}
int main()
{
fin>>k>>n>>m;
for(int i = 0; i<k; i++)
{
int x;
fin>>x;
nodes[x]=i+1;
}
for(int i = 0; i<m; i++)
{
int a, b, c, d;
fin>>a>>b>>c>>d;
graf[a].push_back({b,c,d});
graf[b].push_back({a,c,d});
}
for(int i = 1; i<=n; i++)
fill(dp[i],dp[i]+NMAX,INT_MAX);
dp[1][0] = 0;
cue.push({1,0});
calc();
fout<<res;
return 0;
}