#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long inf = 2e18;
struct node {
  long long d;
  node* l;
  node* r;
  bool vis;
  vector<pair<node*, int>> to;
  node() {
    d = inf;
    vis = false;
  }
} arr[N];
int n, q, s;
int t, v, u, w, l, r;
node st1, st2;
void build(node* n1, node* n2, int low, int hi) {
  if (low == hi) {
    n1->to.push_back({&arr[low], 0});
    arr[low].to.push_back({n2, 0});
    return;
  }
  int mid = (low + hi) / 2;
  n1->l = new node();
  n1->r = new node();
  n2->l = new node();
  n2->r = new node();
  n1->to.push_back({n1->l, 0});
  n1->to.push_back({n1->r, 0});
  (n2->l->to).push_back({n2, 0});
  (n2->r->to).push_back({n2, 0});
  build(n1->l, n2->l, low, mid);
  build(n1->r, n2->r, mid + 1, hi);
}
void addedge(node* x, int low, int hi) {
  if (l > hi || r < low) return;
  if (l <= low && hi <= r) {
    if (t == 2) {
      arr[v].to.push_back({x, w});
    } else {
      x->to.push_back({&arr[v], w});
    }
    return;
  }
  int mid = (low + hi) / 2;
  addedge(x->l, low, mid);
  addedge(x->r, mid + 1, hi);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q >> s;
  build(&st1, &st2, 1, n);
  for (int qq = 1; qq <= q; qq++) {
    cin >> t;
    if (t == 1) {
      cin >> v >> u >> w;
      arr[v].to.push_back({&arr[u], w});
    } else {
      cin >> v >> l >> r >> w;
      if (t == 2)
        addedge(&st1, 1, n);
      else
        addedge(&st2, 1, n);
    }
  }
  priority_queue<pair<long long, node*>, vector<pair<long long, node*>>,
                 greater<pair<long long, node*>>>
      pq;
  arr[s].d = 0;
  pq.push({0, &arr[s]});
  while (!pq.empty()) {
    auto x = pq.top();
    pq.pop();
    node* cur = x.second;
    if (cur->vis) continue;
    cur->vis = true;
    for (auto ed : cur->to) {
      node* nei = ed.first;
      long long wei = ed.second;
      if (nei->d > cur->d + wei) {
        nei->d = cur->d + wei;
        pq.push({nei->d, nei});
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (arr[i].d == inf)
      cout << -1 << " ";
    else
      cout << arr[i].d << " ";
  }
  cout << endl;
  return 0;
}
