#include <iostream>
#include <queue>
#include <cstring>
using namespace std;
const int N = 1e6 + 10;
int h[N], ne[N], e[N], money[N],idx;
void connect(int a,int b,int spend)
{
ne[idx] = h[a];
e[idx] = b;
money[idx] = spend;
h[a] = idx++;
}
bool used[N];
int spend[N];
bool cmp(vector<int>& a, vector<int>& b)
{
return a[0] > b[0];
}
priority_queue<vector<int>, vector<vector<int>>, decltype(&cmp)> q(cmp);
int main()
{
memset(h, -1, sizeof h);
memset(spend, 0x3f, sizeof spend);
int n, m, k; cin >> n >> m >> k;
int st, ed; cin >> st >> ed;
for (int i = 0; i < 6; i++)
{
int a, b, s; cin >> a >> b >> s;
for (int j = 0; j <= k; j++)
{
connect(a + j * n, b + j * n, s);
connect(b + j * n, a + j * n, s);
if (j != k)
{
connect(a + j * n, b + (j+1) * n, 0);
connect(b + j * n, a + (j+1) * n, 0);
}
}
}
q.push({0,st});
spend[st] = 0;
while (!q.empty())
{
auto t = q.top();
q.pop();
int temp_dis = t[0], temp_now = t[1];
if (temp_now % n == ed || used[temp_now])
continue;
used[temp_now] = true;
for (int i = h[temp_now]; i != -1; i = ne[i])
{
int next = e[i], sp = money[i];
if (money[i] + temp_dis < spend[next])
{
spend[next] = money[i] + temp_dis;
q.push({ spend[next],next });
}
}
}
int res = 0x3f3f3f3f;
for (int i = 0; i <= k; i++)
{
res = min(res, spend[ed + i * n]);
}
cout << res << endl;
return 0;
}