#include <bits/stdc++.h>
using namespace std;
const long double EPS = (long double)1e-7;
const long double PI = acos(0) * 2;
bool isZero(const long double& x) { return abs(x) <= EPS; }
int sign(const long double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
long long gcd(long long a, long long b) {
  for (; b; a %= b, swap(a, b)) {
  }
  return abs(a);
}
pair<long long, long long> operator+(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return pair<long long, long long>(a.first + b.first, a.second + b.second);
}
pair<long long, long long> operator-(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return pair<long long, long long>(a.first - b.first, a.second - b.second);
}
pair<long long, long long> operator*(const pair<long long, long long>& a,
                                     const long long& b) {
  return pair<long long, long long>(a.first * b, a.second * b);
}
long long operator*(const pair<long long, long long>& a,
                    const pair<long long, long long>& b) {
  return a.first * b.second - b.first * a.second;
}
long long ccw(const pair<long long, long long>& a,
              const pair<long long, long long>& b,
              const pair<long long, long long>& c) {
  return a * b + b * c + c * a;
}
void fg(vector<int> G[], int a, int b) {
  G[a].emplace_back(b);
  G[b].emplace_back(a);
}
void fg(vector<pair<int, int>> G[], int a, int b, int c) {
  G[a].emplace_back(b, c);
  G[b].emplace_back(a, c);
}
const int MX = 131072;
vector<pair<int, int>> G[MX * 5];
long long D[MX * 5];
int N, Q, K;
void runDijk() {
  priority_queue<pair<long long, int>, vector<pair<long long, int>>,
                 greater<pair<long long, int>>>
      PQ;
  D[K] = 0;
  PQ.emplace(0, K);
  for (long long dst; !PQ.empty();) {
    int idx;
    tie(dst, idx) = PQ.top();
    PQ.pop();
    if (D[idx] < dst) continue;
    for (auto& ed : G[idx]) {
      long long ndst = dst + ed.second;
      int nidx = ed.first;
      if (D[nidx] <= ndst) continue;
      D[nidx] = ndst;
      PQ.emplace(ndst, nidx);
    }
  }
}
vector<int> interval(int s, int e) {
  vector<int> V;
  for (s += MX, e += MX; s <= e; s >>= 1, e >>= 1) {
    if (s & 1) V.emplace_back(s++);
    if (~e & 1) V.emplace_back(e--);
  }
  return V;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 1; i <= MX; i++) {
    G[i].emplace_back(MX * 2 + i - 1, 0);
    G[MX * 4 + i - 2].emplace_back(i, 0);
  }
  for (int i = 2; i < MX * 2; i++) {
    G[i + MX].emplace_back(i / 2 + MX, 0);
    G[i / 2 + MX * 3 - 1].emplace_back(i + MX * 3 - 1, 0);
  }
  fill(D, D + MX * 5, (0x3f3f3f3f3f3f3f3fll));
  cin >> N >> Q >> K;
  for (int t, a, b, c, w; Q--;) {
    cin >> t;
    if (1 == t) {
      cin >> a >> b >> w;
      G[a].emplace_back(b, w);
    } else if (2 == t) {
      cin >> a >> b >> c >> w;
      for (int v : interval(b - 1, c - 1)) G[a].emplace_back(v + MX * 3 - 1, w);
    } else {
      cin >> a >> b >> c >> w;
      for (int v : interval(b - 1, c - 1)) G[v + MX].emplace_back(a, w);
    }
  }
  runDijk();
  for (int i = 1; i <= N; i++)
    cout << ((0x3f3f3f3f3f3f3f3fll) <= D[i] ? -1 : D[i]) << ' ';
  cout << '\n';
  return 0;
}
