/*
* 注意題目要求的是先要滿足最短路的條件下,然後再是看能不能減小花費
* 具體可以看代碼註釋
*/
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 10;
const int MAXM = 2e5 + 10;
const int INF = 0x3f3f3f3f;
struct E{
int to, w, nxt, cost;
}edge[MAXM];
int tot;
int head[MAXN];
priority_queue<pair<int, int>> q;
int dis[MAXN], cost[MAXN];
bool use[MAXN];
int n, m, s, e;
inline void clear(){
tot = 0;
memset(head, -1, sizeof head);
while(!q.empty()) q.pop();
memset(dis, INF, sizeof dis); //未初始化完
memset(cost, INF, sizeof cost); //未初始化完
memset(use, false, sizeof use);
}
inline void addedge(int u, int v, int w, int c){
edge[tot].to = v;
edge[tot].w = w;
edge[tot].cost = c;
edge[tot].nxt = head[u];
head[u] = tot++;
}
inline void dijkstra(){
q.push({0, s});
while(!q.empty()){
auto it = q.top();
q.pop();
int id = it.second;
if(use[id]) continue;
use[id] = true;
for(int i = head[id]; ~i; i = edge[i].nxt){
int to = edge[i].to;
int w = edge[i].w;
int c = edge[i].cost;
if(dis[id] + w < dis[to]){ //找到更短的路了,dis,cost都更新
dis[to] = dis[id] + w;
cost[to] = cost[id] + c;
q.push({-dis[to], to});
}
if(dis[id] + w == dis[to] && cost[id] + c < cost[to]) cost[to] = cost[id] + c; //多條最短路距離相等,更新最小花費
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//cout << setiosflags(ios::fixed) << setprecision(1); //保留小數點後1位
//cout << setprecision(1); //保留1位有效數字
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
while(cin >> n >> m){
if(n == 0 && m == 0) break;
clear();
for(int i = 1; i <= m; ++i){
int u, v, w, c;
cin >> u >> v >> w >> c;
addedge(u, v, w, c);
addedge(v, u, w, c);
}
cin >> s >> e;
dis[s] = cost[s] = 0;
dijkstra();
cout << dis[e] << " " << cost[e] << endl;
}
return 0;
}