#include <bits/stdc++.h>
using namespace std;
#ifdef osayes
#include "header.cpp"
#endif // osayes
void Main();
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
template<typename T>bool updmin(T &a, T b) {  if (b < a) { a = b; return 1; } return 0; }
template<typename T1,typename T2,typename T3>struct _three_element_struct{T1&first;T2&second;T3&third;_three_element_struct(T1&first,T2&second,T3&third):first(first),second(second),third(third){}};
template<typename T1,typename T2,typename T3>_three_element_struct<T1,T2,T3>gettuple(tuple<T1,T2,T3>&a){return _three_element_struct<T1,T2,T3>(get<0>(a),get<1>(a),get<2>(a));}
template<typename T>
struct ShortestPath {
  map<pair<int, int>, T> dist;
  vector<vector<pair<int, T>>> graph;
  T &getdist(int i, int j) {
    if (i > j) swap(i, j);
    auto it = dist.find({i, j});
    if (it == dist.end()) return dist[{i, j}] = numeric_limits<T>::max() / 2;
    return it->second;
  }
  ShortestPath(vector<vector<pair<int, T>>> &graph): graph(graph) {}
  void go(int k) {
    priority_queue<tuple<T, int, int>, vector<tuple<T, int, int>>, greater<tuple<T, int, int>>> q;
    for (int i = 0; i < graph.size(); i++) {
      dist[{i, i}] = 0;
      q.push(make_tuple(0, i, i));
    }
    map<pair<int, int>, bool> vis;
    while (!q.empty()) {
      auto top = q.top();
      q.pop();
      auto three = gettuple(top);
      if (vis[{three.second, three.third}]) continue;
      if (three.second < three.third) {
        if (--k == 0) {
          cout << three.first << endl;
          return;
        }
      }
      vis[{three.second, three.third}] = 1;
      for (auto &p: graph[three.third]) {
        if (updmin(getdist(three.second, p.first), three.first + p.second)) {
          q.push(make_tuple(getdist(three.second, p.first), three.second, p.first));
        }
      }
    }
  }
};
void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<pair<int, long long>>> graph(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    graph[u].push_back({v, w});
    graph[v].push_back({u, w});
  }
  ShortestPath<long long> sp(graph);
  sp.go(k);
}


#include <bits/stdc++.h>
using namespace std;
#ifdef osayes
#include "header.cpp"
#endif // osayes
void Main();
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
template<typename T>bool updmin(T &a, T b) {  if (b < a) { a = b; return 1; } return 0; }
template<typename T1,typename T2,typename T3>struct _three_element_struct{T1&first;T2&second;T3&third;_three_element_struct(T1&first,T2&second,T3&third):first(first),second(second),third(third){}};
template<typename T1,typename T2,typename T3>_three_element_struct<T1,T2,T3>gettuple(tuple<T1,T2,T3>&a){return _three_element_struct<T1,T2,T3>(get<0>(a),get<1>(a),get<2>(a));}
template<typename T>
struct ShortestPath {
  vector<vector<pair<int, T>>> graph;
  ShortestPath(vector<vector<pair<int, T>>> &graph): graph(graph) {}
  void go(int k) {
    priority_queue<tuple<T, int, int>, vector<tuple<T, int, int>>, greater<tuple<T, int, int>>> q;
    for (int i = 0; i < graph.size(); i++) {
      q.push(make_tuple(0, i, i));
    }
    map<pair<int, int>, bool> visit;
    while (!q.empty()) {
      auto top = q.top();
      q.pop();
      auto three = gettuple(top);
      if (visit[{three.second, three.third}]) continue;
      visit[{three.second, three.third}] = 1;
      if (three.second < three.third) {
        if (--k == 0) {
          cout << three.first << endl;
          return;
        }
      }
      for (int i = 0; i < min(k, (int)graph[three.third].size()); i++) {
        auto p = graph[three.third][i];
        q.push(make_tuple(three.first + p.second, three.second, p.first));
        q.push(make_tuple(three.first + p.second, p.first, three.second));
      }
    }
  }
};
void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<pair<int, long long>>> graph(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    graph[u].push_back({v, w});
    graph[v].push_back({u, w});
  }
  for (int i = 0; i < n; i++) {
    sort(graph[i].begin(), graph[i].end(), [](pair<int, long long> p1, pair<int, long long> p2){ return p1.second < p2.second; });
  }
  ShortestPath<long long> sp(graph);
  sp.go(k);
}


#include <bits/stdc++.h>
using namespace std;
#ifdef osayes
#include "header.cpp"
#endif // osayes
using tiii = tuple<int, int, int>;
void Main();
int main() { ios::sync_with_stdio(0); while (~cin.peek()) Main(), cin.get(); return 0; }
struct UnionSet {
  vector<int> f;
  UnionSet(int n) { f.resize(n + 1); for (int i = 1; i <= n; i++) f[i] = i; };
  int getf(int cur) {
    return f[cur] == cur? cur : f[cur] = getf(f[cur]);
  }
  void merge(int u, int v) {
    f[getf(u)] = getf(v);
  }
};
void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<tiii> edge;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edge.push_back(tiii{w, u, v});
  }
  sort(edge.begin(), edge.end());
  vector<int> id(n + 1, -1);
  int cur = 0;
  for (int i = 0; i < min(k, m); i++) {
    int u, v, w;
    tie(w, u, v) = edge[i];
    if (id[u] == -1) id[u] = cur++;
    if (id[v] == -1) id[v] = cur++;
    u = id[u];
    v = id[v];
    edge[i] = tie(w, u, v);
  }
  UnionSet us(cur);
  vector<vector<int>> dist(cur, vector<int>(cur, 1e9 + 7));
  for (int i = 0; i < min(k, m); i++) {
    int u, v, w;
    tie(w, u, v) = edge[i];
    us.merge(u, v);
    dist[u][v] = dist[v][u] = w;
  }
  vector<vector<int>> component(cur);
  for (int i = 0; i < cur; i++) {
    component[us.getf(i)].push_back(i);
  }
  auto floyed = [&](vector<int> &c) {
    int n = c.size();
    vector<vector<int>> d(n, vector<int>(n, 1e9 + 7));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = dist[c[i]][c[j]];
      }
    }
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
    vector<int> res;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        res.push_back(d[i][j]);
      }
    }
    return res;
  };
  auto mergearray = [&](vector<int> a, vector<int> b) {
    vector<int> res(a.size() + b.size());
    merge(a.begin(), a.end(), b.begin(), b.end(), res.begin());
    sort(res.begin(), res.end());
    return vector<int>(res.begin(), res.begin() + min(k, (int)res.size()));
  };
  vector<int> ans;
  for (int i = 0; i < cur; i++) {
    if (component[i].size()) {
      ans = mergearray(ans, floyed(component[i]));
    }
  }
  cout << ans[k - 1] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef osayes
#include "header.cpp"
#endif // osayes
void Main();
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
using tiii = tuple<int, int, int>;
template<typename T>bool updmin(T &a, T b) {  if (b < a) { a = b; return 1; } return 0; }
template<typename T1,typename T2,typename T3>struct _three_element_struct{T1&first;T2&second;T3&third;_three_element_struct(T1&first,T2&second,T3&third):first(first),second(second),third(third){}};
template<typename T1,typename T2,typename T3>_three_element_struct<T1,T2,T3>gettuple(tuple<T1,T2,T3>&a){return _three_element_struct<T1,T2,T3>(get<0>(a),get<1>(a),get<2>(a));}
template<typename T>
struct ShortestPath {
  vector<T> dist;
  vector<vector<pair<int, T>>> graph;
  int source;
  ShortestPath(vector<vector<pair<int, T>>> &graph, int source = 0): graph(graph), source(source) {
    dist.resize(graph.size(), numeric_limits<T>::max() >> 1);
  }
  void go() {
    dist[source] = 0;
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<pair<T, int>>> q;
    q.push({0, source});
    vector<int> vis(graph.size());
    while (!q.empty()) {
      auto top = q.top();
      q.pop();
      if (vis[top.second]) continue;
      vis[top.second] = 1;
      for (auto &p: graph[top.second]) {
        if (updmin(dist[p.first], dist[top.second] + p.second)) {
          q.push({dist[p.first], p.first});
        }
      }
    }
  }
};
void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<tiii> edge;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edge.push_back(tiii{w, u, v});
  }
  sort(edge.begin(), edge.end());
  vector<int> id(n + 1, -1);
  int cur = 0;
  for (int i = 0; i < min(k, m); i++) {
    auto x = gettuple(edge[i]);
    if (id[x.second] == -1) id[x.second] = cur++;
    if (id[x.third] == -1) id[x.third] = cur++;
    x.second = id[x.second];
    x.third = id[x.third];
  }
  vector<vector<pair<int, long long>>> graph(cur);
  for (int i = 0; i < min(k, m); i++) {
    auto x = gettuple(edge[i]);
    graph[x.second].push_back({x.third, x.first});
    graph[x.third].push_back({x.second, x.first});
  }
  vector<long long> ans;
  for (int source = 0; source < cur; source++) {
    ShortestPath<long long> sp(graph, source);
    sp.go();
    for (int i = source + 1; i < cur; i++) {
      ans.push_back(sp.dist[i]);
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans[k - 1] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef osayes
#include "header.cpp"
#endif // osayes
using tiii = tuple<int, int, int>;
void Main();
int main() { ios::sync_with_stdio(0); while (~cin.peek()) Main(), cin.get(); return 0; }
struct UnionSet {
  vector<int> f;
  UnionSet(int n) { f.resize(n + 1); for (int i = 1; i <= n; i++) f[i] = i; };
  int getf(int cur) {
    return f[cur] == cur? cur : f[cur] = getf(f[cur]);
  }
  void merge(int u, int v) {
    f[getf(u)] = getf(v);
  }
};
void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<tiii> edge;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edge.push_back(tiii{w, u, v});
  }
  sort(edge.begin(), edge.end());
  vector<int> id(n + 1, -1);
  int cur = 0;
  for (int i = 0; i < min(k, m); i++) {
    int u, v, w;
    tie(w, u, v) = edge[i];
    if (id[u] == -1) id[u] = cur++;
    if (id[v] == -1) id[v] = cur++;
    u = id[u];
    v = id[v];
    edge[i] = tie(w, u, v);
  }
  UnionSet us(cur);
  vector<vector<long long>> dist(cur, vector<long long>(cur, 1e16 + 7));
  for (int i = 0; i < min(k, m); i++) {
    int u, v, w;
    tie(w, u, v) = edge[i];
    us.merge(u, v);
    dist[u][v] = dist[v][u] = w;
  }
  vector<vector<int>> component(cur);
  for (int i = 0; i < cur; i++) {
    component[us.getf(i)].push_back(i);
  }
  auto floyed = [&](vector<int> &c) {
    int n = c.size();
    vector<vector<long long>> d(n, vector<long long>(n, 1e16 + 7));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = dist[c[i]][c[j]];
      }
    }
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
    vector<long long> res;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        res.push_back(d[i][j]);
      }
    }
    return res;
  };
  auto mergearray = [&](vector<long long> a, vector<long long> b) {
    vector<long long> res(a.size() + b.size());
    merge(a.begin(), a.end(), b.begin(), b.end(), res.begin());
    sort(res.begin(), res.end());
    return vector<long long>(res.begin(), res.begin() + min(k, (int)res.size()));
  };
  vector<long long> ans;
  for (int i = 0; i < cur; i++) {
    if (component[i].size()) {
      ans = mergearray(ans, floyed(component[i]));
    }
  }
  cout << ans[k - 1] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#ifdef osayes
#include "header.cpp"
#endif // osayes
void Main();
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
template<typename T>bool updmin(T &a, T b) {  if (b < a) { a = b; return 1; } return 0; }
template<typename T1,typename T2,typename T3>struct _three_element_struct{T1&first;T2&second;T3&third;_three_element_struct(T1&first,T2&second,T3&third):first(first),second(second),third(third){}};
template<typename T1,typename T2,typename T3>_three_element_struct<T1,T2,T3>gettuple(tuple<T1,T2,T3>&a){return _three_element_struct<T1,T2,T3>(get<0>(a),get<1>(a),get<2>(a));}
template<typename T>
struct ShortestPath {
  map<pair<int, int>, T> dist;
  vector<vector<pair<int, T>>> graph;
  T &getdist(int i, int j) {
    if (i > j) swap(i, j);
    auto it = dist.find({i, j});
    if (it == dist.end()) return dist[{i, j}] = numeric_limits<T>::max() / 2;
    return it->second;
  }
  ShortestPath(vector<vector<pair<int, T>>> &graph): graph(graph) {}
  void go(int k) {
    priority_queue<tuple<T, int, int>, vector<tuple<T, int, int>>, greater<tuple<T, int, int>>> q;
    for (int i = 0; i < graph.size(); i++) {
      dist[{i, i}] = 0;
      q.push(make_tuple(0, i, i));
    }
    while (!q.empty()) {
      auto top = q.top();
      q.pop();
      auto three = gettuple(top);
      if (three.first > getdist(three.second, three.third)) continue;
      if (three.second < three.third) {
        if (--k == 0) {
          cout << three.first << endl;
          return;
        }
      }
      for (auto &p: graph[three.third]) {
        if (updmin(getdist(three.second, p.first), three.first + p.second)) {
          q.push(make_tuple(getdist(three.second, p.first), three.second, p.first));
          q.push(make_tuple(getdist(three.second, p.first), p.first, three.second));
        }
      }
    }
  }
};
void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<pair<int, long long>>> graph(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    graph[u].push_back({v, w});
    graph[v].push_back({u, w});
  }
  ShortestPath<long long> sp(graph);
  sp.go(k);
}


#include <bits/stdc++.h>
using namespace std;
#ifdef osayes
#include "header.cpp"
#endif // osayes
void Main();
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
template<typename T>bool updmin(T &a, T b) {  if (b < a) { a = b; return 1; } return 0; }
template<typename T1,typename T2,typename T3>struct _three_element_struct{T1&first;T2&second;T3&third;_three_element_struct(T1&first,T2&second,T3&third):first(first),second(second),third(third){}};
template<typename T1,typename T2,typename T3>_three_element_struct<T1,T2,T3>gettuple(tuple<T1,T2,T3>&a){return _three_element_struct<T1,T2,T3>(get<0>(a),get<1>(a),get<2>(a));}
template<typename T>
struct ShortestPath {
  map<pair<int, int>, T> dist;
  vector<vector<pair<int, T>>> graph;
  T &getdist(int i, int j) {
    if (i > j) swap(i, j);
    auto it = dist.find({i, j});
    if (it == dist.end()) return dist[{i, j}] = numeric_limits<T>::max() / 2;
    return it->second;
  }
  ShortestPath(vector<vector<pair<int, T>>> &graph): graph(graph) {}
  void go(int k) {
    priority_queue<tuple<T, int, int>, vector<tuple<T, int, int>>, greater<tuple<T, int, int>>> q;
    for (int i = 0; i < graph.size(); i++) {
      dist[{i, i}] = 0;
      q.push(make_tuple(0, i, i));
    }
    map<pair<int, int>, bool> vis;
    while (!q.empty()) {
      auto top = q.top();
      q.pop();
      auto three = gettuple(top);
      if (vis[{three.second, three.third}]) continue;
      if (three.second < three.third) {
        if (--k == 0) {
          cout << three.first << endl;
          return;
        }
      }
      vis[{three.second, three.third}] = 1;
      for (auto &p: graph[three.third]) {
        if (updmin(getdist(three.second, p.first), three.first + p.second)) {
          q.push(make_tuple(getdist(three.second, p.first), three.second, p.first));
          q.push(make_tuple(getdist(three.second, p.first), p.first, three.second));
        }
      }
    }
  }
};
void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<pair<int, long long>>> graph(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    graph[u].push_back({v, w});
    graph[v].push_back({u, w});
  }
  ShortestPath<long long> sp(graph);
  sp.go(k);
}


#include <bits/stdc++.h>
using namespace std;
#ifdef osayes
#include "header.cpp"
#endif // osayes
void Main();
int main() { ios::sync_with_stdio(0); cin.tie(0); while (~cin.peek()) Main(), cin.get(); return 0; }
template<typename T>bool updmin(T &a, T b) {  if (b < a) { a = b; return 1; } return 0; }
template<typename T1,typename T2,typename T3>struct _three_element_struct{T1&first;T2&second;T3&third;_three_element_struct(T1&first,T2&second,T3&third):first(first),second(second),third(third){}};
template<typename T1,typename T2,typename T3>_three_element_struct<T1,T2,T3>gettuple(tuple<T1,T2,T3>&a){return _three_element_struct<T1,T2,T3>(get<0>(a),get<1>(a),get<2>(a));}
template<typename T>
struct ShortestPath {
  map<pair<int, int>, T> dist;
  vector<vector<pair<int, T>>> graph;
  T &getdist(int i, int j) {
    auto it = dist.find({i, j});
    if (it == dist.end()) return dist[{i, j}] = numeric_limits<T>::max() / 2;
    return it->second;
  }
  ShortestPath(vector<vector<pair<int, T>>> &graph): graph(graph) {}
  void go(int k) {
    priority_queue<tuple<T, int, int>, vector<tuple<T, int, int>>, greater<tuple<T, int, int>>> q;
    for (int i = 0; i < graph.size(); i++) {
      dist[{i, i}] = 0;
      q.push(make_tuple(0, i, i));
    }
    map<pair<int, int>, bool> vis;
    while (!q.empty()) {
      auto top = q.top();
      q.pop();
      auto three = gettuple(top);
      if (vis[{three.second, three.third}]) continue;
      if (three.second < three.third) {
        if (--k == 0) {
          cout << three.first << endl;
          return;
        }
      }
      vis[{three.second, three.third}] = 1;
      for (auto &p: graph[three.third]) {
        if (updmin(getdist(three.second, p.first), three.first + p.second)) {
          q.push(make_tuple(getdist(three.second, p.first), three.second, p.first));
        }
      }
    }
  }
};
void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<vector<pair<int, long long>>> graph(n);
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    u--;
    v--;
    graph[u].push_back({v, w});
    graph[v].push_back({u, w});
  }
  ShortestPath<long long> sp(graph);
  sp.go(k);
}


#include <bits/stdc++.h>
using namespace std;
#ifdef osayes
#include "header.cpp"
#endif // osayes
void Main();
int main() { ios::sync_with_stdio(0); while (~cin.peek()) Main(), cin.get(); return 0; }
using tiii = tuple<int, int, int>;
template<typename T>
struct _vector: vector<T> {
  using vector<T>::vector;
  T &operator[](int x) {
    return this->at(x);
  }
};
#define vector _vector
struct UnionSet {
  vector<int> f;
  UnionSet(int n) { f.resize(n + 1); for (int i = 1; i <= n; i++) f[i] = i; };
  int getf(int cur) {
    return f[cur] == cur? cur : f[cur] = getf(f[cur]);
  }
  void merge(int u, int v) {
    f[getf(u)] = getf(v);
  }
};
void Main() {
  int n, m, k;
  cin >> n >> m >> k;
  vector<tiii> edge;
  for (int i = 0; i < m; i++) {
    int u, v, w;
    cin >> u >> v >> w;
    edge.push_back(tiii{w, u, v});
  }
  sort(edge.begin(), edge.end());
  vector<int> id(n + 1, -1);
  int cur = 0;
  for (int i = 0; i < min(k, m); i++) {
    int u, v, w;
    tie(w, u, v) = edge[i];
    if (id[u] == -1) id[u] = cur++;
    if (id[v] == -1) id[v] = cur++;
    u = id[u];
    v = id[v];
    edge[i] = tie(w, u, v);
  }
  UnionSet us(cur);
  vector<vector<long long>> dist(cur, vector<long long>(cur, 1e16 + 7));
  for (int i = 0; i < min(k, m); i++) {
    int u, v, w;
    tie(w, u, v) = edge[i];
    us.merge(u, v);
    dist[u][v] = dist[v][u] = w;
  }
  vector<vector<int>> component(cur);
  for (int i = 0; i < cur; i++) {
    component[us.getf(i)].push_back(i);
  }
  auto floyed = [&](vector<int> &c) {
    int n = c.size();
    vector<vector<long long>> d(n, vector<long long>(n, 1e16 + 7));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = dist[c[i]][c[j]];
      }
    }
    for (int k = 0; k < n; k++) {
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
        }
      }
    }
    vector<long long> res;
    for (int i = 0; i < n; i++) {
      for (int j = i + 1; j < n; j++) {
        res.push_back(d[i][j]);
      }
    }
    return res;
  };
  auto mergearray = [&](vector<long long> a, vector<long long> b) {
    vector<long long> res(a.size() + b.size());
    merge(a.begin(), a.end(), b.begin(), b.end(), res.begin());
    sort(res.begin(), res.end());
    return vector<long long>(res.begin(), res.begin() + min(k, (int)res.size()));
  };
  vector<long long> ans;
  for (int i = 0; i < cur; i++) {
    if (component[i].size()) {
      ans = mergearray(ans, floyed(component[i]));
    }
  }
  cout << ans[k - 1] << endl;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 4e2 + 10;
const int inf = 1e9 + 7;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
int f[Maxk][Maxk];
int d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= k ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint k = 1 ; k <= _cnt ; ++k)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][k] + f[k][j] < f[i][j])   f[i][j] = f[i][k] + f[k][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 8e2 + 10;
const int inf = 1e18;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
long long f[Maxk][Maxk];
long long d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    int now = k;
	while (G[now + 1].w == G[now].w) {
		++now;
		book[G[now].from] = 1, book[G[now].to] = 1;
	}
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= now ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 8e2 + 10;
const int inf = 1e18;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
long long f[Maxk][Maxk];
long long d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= now ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 8e2 + 10;
const long inf = 1e18;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
long long f[Maxk][Maxk];
long long d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    int now = k;
	while (G[now + 1].w == G[now].w) {
		++now;
		book[G[now].from] = 1, book[G[now].to] = 1;
	}
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= now ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 4e2 + 10;
const int inf = 1e9 + 7;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
int f[Maxk][Maxk];
int d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    int now = k;
	while (G[now + 1].w == G[now].w) {
		++now;
		book[G[now].from] = 1, book[G[now].to] = 1;
	}
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= now ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 8e2 + 10;
const long long inf = 1e18;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
long long f[Maxk][Maxk];
long long d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    int now = k;
	while (G[now + 1].w == G[now].w) {
		++now;
		book[G[now].from] = 1, book[G[now].to] = 1;
	}
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= now ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 8e2 + 10;
const int inf = 1e18;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
long long f[Maxk][Maxk];
long long d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= k ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 2e3 + 10;
const long long inf = 1e18;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
long long f[Maxk][Maxk];
long long d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    int now = k;
	while (G[now + 1].w == G[now].w) {
		++now;
		book[G[now].from] = 1, book[G[now].to] = 1;
	}
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= now ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 4e2 + 10;
const int inf = 1e9 + 7;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
long long f[Maxk][Maxk];
long long d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    int now = k;
	while (G[now + 1].w == G[now].w) {
		++now;
		book[G[now].from] = 1, book[G[now].to] = 1;
	}
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= now ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 8e2 + 10;
const long long inf = 1e18;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
long long f[Maxk][Maxk];
long long d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= k ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

#define rint register int

using namespace std;

const int Maxn = 2e5 + 10;
const int Maxk = 4e2 + 10;
const int inf = 1e18;

struct edge {
    int from, to, w;
}G[Maxn];

int _index, _cnt, _tot;
int n, m, k;
int book[Maxn], mp[Maxn];
long long f[Maxk][Maxk];
long long d[Maxn];

bool operator <(const edge &a, const edge &b) {
    return a.w < b.w;
}

template <typename T> inline void read(T& x) {
    x = 0; char ch = getchar();
    while (!isdigit(ch)) ch = getchar();
    while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
}

template <typename T, typename... Args>

inline void read(T& x, Args&... args) { read(x); read(args...); }

int main() {
    read(n, m, k);
    for (rint i = 1 ; i <= m ; ++i)   read(G[i].from, G[i].to, G[i].w);
    sort(G + 1, G + m + 1);
    for (rint i = 1 ; i <= k ; ++i)   book[G[i].from] = 1, book[G[i].to] = 1;
    int now = k;
	while (G[now + 1].w == G[now].w) {
		++now;
		book[G[now].from] = 1, book[G[now].to] = 1;
	}
    for (rint i = 1 ; i < Maxn ; ++i) {
        if (book[i] == 1) {
            mp[i] = ++_cnt;
        }
    }
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    f[i][j] = inf;

    for (rint i = 1 ; i <= now ; ++i) {
        f[mp[G[i].from]][mp[G[i].to]] = G[i].w;
        f[mp[G[i].to]][mp[G[i].from]] = G[i].w;
    }
    for (rint p = 1 ; p <= _cnt ; ++p)
    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j <= _cnt ; ++j)
    if (f[i][p] + f[p][j] < f[i][j])   f[i][j] = f[i][p] + f[p][j];

    for (rint i = 1 ; i <= _cnt ; ++i)
    for (rint j = 1 ; j < i ; ++j)
    d[++_tot] = f[i][j];
    sort(d + 1, d + _tot + 1);
    cout << d[k] << endl;
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
inline int read()
{
    int f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')
            f=-1;
    }while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}

int n,m,k;
struct edge
{
    int x;
    int y;
    int v;
}b[200001];
ll vv[401][401];
ll dis[401][401];
map<int,int> p;
int tot,num;
ll s[160001];

inline bool compare(edge a,edge b)
{
    return a.v<b.v;
}
int main()
{
    n=read();
    m=read();
    k=read();
    for(int i=1;i<=m;i++)
    {
        b[i].x=read();
        b[i].y=read();
        b[i].v=read();
    }

    sort(b+1,b+m+1,compare);
    for(int i=1;i<=400;i++)
    {
        for(int j=1;j<=400;j++)
            vv[i][j]=1e18;
        vv[i][i]=0;
    }
    for(int i=1;i<=min(m,k);i++)
    {
        if(p.find(b[i].x)==p.end())
            p[b[i].x]=++tot;
        if(p.find(b[i].y)==p.end())
            p[b[i].y]=++tot;
        vv[p[b[i].x]][p[b[i].y]]=vv[p[b[i].y]][p[b[i].x]]=b[i].v;
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
            dis[i][j]=1e18;
        dis[i][i]=0;
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
        {
            for(int k=1;k<=tot;k++)
                dis[i][j]=min(dis[i][j],(ll)vv[i][k]+vv[k][j]);
        }
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=i+1;j<=tot;j++)
        {
            if(dis[i][j]!=1e18&&dis[i][j])
                s[++num]=dis[i][j];
        }
    }
    sort(s+1,s+num+1);

    printf("%I64d\n",s[k]);
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<set>
#define ll long long
using namespace std;
inline int read()
{
    int f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')
            f=-1;
    }while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
const int N=2e5;
const int M=2e5;
const int K=400;

int n,m,k;
struct edge
{
    int x;
    int y;
    int v;
}b[M+1];
ll dis[2*K+1][2*K+1];
set<int> ss;
int to[N+1];
int tot,num;
ll s[2*K*2*K+1];

inline bool compare(edge a,edge b)
{
    return a.v<b.v;
}
int main()
{
    n=read();
    m=read();
    k=read();
    for(int i=1;i<=m;i++)
    {
        b[i].x=read();
        b[i].y=read();
        b[i].v=read();
    }

    sort(b+1,b+m+1,compare);
    ss.insert(0);
    for(int i=1;i<=min(m,k);i++)
    {
        ss.insert(b[i].x);
        ss.insert(b[i].y);
    }
    for(set<int>::iterator it=ss.begin()+1;it!=ss.end();it++)
        to[*it]=++tot;
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
            dis[i][j]=1e18;
        dis[i][i]=0;
    }
    for(int i=1;i<=min(m,k);i++)
    {
        dis[to[b[i].x]][to[b[i].y]]=b[i].v;
        dis[to[b[i].y]][to[b[i].x]]=b[i].v;
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
        {
            for(int k=1;k<=tot;k++)
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
        }
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=i+1;j<=tot;j++)
        {
            if(dis[i][j]<1e18&&dis[i][j])
                s[++num]=dis[i][j];
        }
    }
    sort(s+1,s+num+1);

    printf("%I64d\n",s[k]);
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<map>
#define ll long long
using namespace std;
inline int read()
{
    int f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')
            f=-1;
    }while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}

int n,m,k;
struct edge
{
    int x;
    int y;
    int v;
}b[200001];
ll vv[401][401];
ll dis[401][401];
map<int,int> p;
int tot,num;
ll s[160001];

inline bool compare(edge a,edge b)
{
    return a.v<b.v;
}
int main()
{
    n=read();
    m=read();
    k=read();
    for(int i=1;i<=m;i++)
    {
        b[i].x=read();
        b[i].y=read();
        b[i].v=read();
    }

    sort(b+1,b+m+1,compare);
    for(int i=1;i<=400;i++)
    {
        for(int j=1;j<=400;j++)
            vv[i][j]=1e18;
        vv[i][i]=0;
    }
    for(int i=1;i<=min(m,k);i++)
    {
        if(p.find(b[i].x)==p.end())
            p[b[i].x]=++tot;
        if(p.find(b[i].y)==p.end())
            p[b[i].y]=++tot;
        vv[p[b[i].x]][p[b[i].y]]=vv[p[b[i].y]][p[b[i].x]]=b[i].v;
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
            dis[i][j]=1e18;
        dis[i][i]=0;
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
        {
            for(int k=1;k<=tot;k++)
                dis[i][j]=min(dis[i][j],(ll)vv[i][k]+vv[k][j]);
            if(dis[i][j]!=1e18&&dis[i][j])
                s[++num]=dis[i][j];
        }
    }
    sort(s+1,s+num+1);

    printf("%I64d\n",s[2*k]);
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<set>
#define ll long long
using namespace std;
inline int read()
{
    int f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')
            f=-1;
    }while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
const int N=2e5;
const int M=2e5;
const int K=400;

int n,m,k;
struct edge
{
    int x;
    int y;
    int v;
}b[M+1];
ll dis[2*K+1][2*K+1];
set<int> ss;
int to[N+1];
int tot,num;
ll s[2*K*2*K+1];

inline bool compare(edge a,edge b)
{
    return a.v<b.v;
}
int main()
{
    n=read();
    m=read();
    k=read();
    for(int i=1;i<=m;i++)
    {
        b[i].x=read();
        b[i].y=read();
        b[i].v=read();
    }

    sort(b+1,b+m+1,compare);
    ss.insert(0);
    for(int i=1;i<=min(m,k);i++)
    {
        ss.insert(b[i].x);
        ss.insert(b[i].y);
    }
    for(set<int>::iterator it=ss.begin();it!=ss.end();it++)
    {
        if(*it!=0)
            to[*it]=++tot;
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
            dis[i][j]=1e18;
        dis[i][i]=0;
    }
    for(int i=1;i<=min(m,k);i++)
    {
        dis[to[b[i].x]][to[b[i].y]]=b[i].v;
        dis[to[b[i].y]][to[b[i].x]]=b[i].v;
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
        {
            for(int k=1;k<=tot;k++)
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
        }
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=i+1;j<=tot;j++)
        {
            if(dis[i][j]<1e18&&dis[i][j])
                s[++num]=dis[i][j];
        }
    }
    sort(s+1,s+num+1);

    printf("%I64d\n",s[k]);
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<set>
#define ll long long
using namespace std;
inline int read()
{
    int f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')
            f=-1;
    }while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
const int N=2e5;
const int M=2e5;
const int K=400;

int n,m,k;
struct edge
{
    int x;
    int y;
    int v;
}b[M+1];
ll dis[2*K+1][2*K+1];
set<int> ss;
int to[N+1];
int tot,num;
ll s[2*K*2*K+1];

inline bool compare(edge a,edge b)
{
    return a.v<b.v;
}
int main()
{
    n=read();
    m=read();
    k=read();
    for(int i=1;i<=m;i++)
    {
        b[i].x=read();
        b[i].y=read();
        b[i].v=read();
    }

    sort(b+1,b+m+1,compare);
    ss.insert(0);
    for(int i=1;i<=min(m,k);i++)
    {
        ss.insert(b[i].x);
        ss.insert(b[i].y);
    }
    for(set<int>::iterator it=ss.begin();it!=ss.end();it++)
    {
        if(*it!=0)
            to[*it]=++tot;
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
            dis[i][j]=1e18;
        dis[i][i]=0;
    }
    for(int i=1;i<=min(m,k);i++)
    {
        dis[to[b[i].x]][to[b[i].y]]=b[i].v;
        dis[to[b[i].y]][to[b[i].x]]=b[i].v;
    }
    for(int l=1;l<=tot;l++)
    {
        for(int i=1;i<=tot;i++)
        {
            for(int j=1;j<=tot;j++)
                dis[i][j]=min(dis[i][j],dis[i][l]+dis[l][j]);
        }
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=i+1;j<=tot;j++)
        {
            if(dis[i][j]<1e18&&dis[i][j])
                s[++num]=dis[i][j];
        }
    }
    sort(s+1,s+num+1);

    printf("%I64d\n",s[k]);
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<set>
#define ll long long
using namespace std;
inline int read()
{
    int f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')
            f=-1;
    }while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
const int N=2e5;
const int M=2e5;
const int K=400;

int n,m,k;
struct edge
{
    int x;
    int y;
    int v;
}b[M+1];
ll dis[2*K+1][2*K+1];
set<int> ss;
int to[N+1];
int tot,num;
ll s[2*K*2*K+1];

inline bool compare(edge a,edge b)
{
    return a.v<b.v;
}
int main()
{
    n=read();
    m=read();
    k=read();
    for(int i=1;i<=m;i++)
    {
        b[i].x=read();
        b[i].y=read();
        b[i].v=read();
    }

    sort(b+1,b+m+1,compare);
    ss.insert(0);
    for(int i=1;i<=min(m,k);i++)
    {
        ss.insert(b[i].x);
        ss.insert(b[i].y);
    }
    for(set<int>::iterator it=ss.begin();it!=ss.end();it++)
        to[*it]=++tot;
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
            dis[i][j]=1e18;
        dis[i][i]=0;
    }
    for(int i=1;i<=min(m,k);i++)
    {
        dis[to[b[i].x]][to[b[i].y]]=b[i].v;
        dis[to[b[i].y]][to[b[i].x]]=b[i].v;
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
        {
            for(int k=1;k<=tot;k++)
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
        }
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=i+1;j<=tot;j++)
        {
            if(dis[i][j]<1e18&&dis[i][j])
                s[++num]=dis[i][j];
        }
    }
    sort(s+1,s+num+1);

    printf("%I64d\n",s[k]);
    return 0;
}


#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<set>
#define ll long long
using namespace std;
inline int read()
{
    int f=1,x=0;
    char ch;
    do
    {
        ch=getchar();
        if(ch=='-')
            f=-1;
    }while(ch<'0'||ch>'9');
    do
    {
        x=x*10+ch-'0';
        ch=getchar();
    }while(ch>='0'&&ch<='9');
    return f*x;
}
const int N=2e5;
const int M=2e5;
const int K=400;

int n,m,k;
struct edge
{
    int x;
    int y;
    int v;
}b[M+1];
ll dis[2*K+1][2*K+1];
set<int> ss;
int to[N+1];
int tot,num;
ll s[2*K*2*K+1];

inline bool compare(edge a,edge b)
{
    return a.v<b.v;
}
int main()
{
    n=read();
    m=read();
    k=read();
    for(int i=1;i<=m;i++)
    {
        b[i].x=read();
        b[i].y=read();
        b[i].v=read();
    }

    sort(b+1,b+m+1,compare);
    ss.insert(0);
    for(int i=1;i<=min(m,k);i++)
    {
        ss.insert(b[i].x);
        ss.insert(b[i].y);
    }
    for(set<int>::iterator it=ss.begin();it!=ss.end();it++)
        to[*it]=++tot;
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
            dis[i][j]=1e18;
        dis[i][i]=0;
    }
    for(int i=1;i<=min(m,k);i++)
    {
        dis[to[b[i].x]][to[b[i].y]]=min(dis[to[b[i].x]][to[b[i].y]],(ll)b[i].v);
        dis[to[b[i].y]][to[b[i].x]]=min(dis[to[b[i].x]][to[b[i].y]],(ll)b[i].v);
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=1;j<=tot;j++)
        {
            for(int k=1;k<=tot;k++)
                dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
        }
    }
    for(int i=1;i<=tot;i++)
    {
        for(int j=i+1;j<=tot;j++)
        {
            if(dis[i][j]<1e18&&dis[i][j])
                s[++num]=dis[i][j];
        }
    }
    sort(s+1,s+num+1);

    printf("%I64d\n",s[k]);
    return 0;
}


/*input
7 15 18
2 6 3
5 7 4
6 5 4
3 6 9
6 7 7
1 6 4
7 1 6
7 2 1
4 3 2
3 2 8
5 3 6
2 5 5
3 7 9
4 1 8
2 1 1
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	int N, M, k;
	cin >> N >> M >> k;
	ll atstumas[N][N];
	const ll INF = 1e16;
	for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
			atstumas[i][j] = INF;
		atstumas[i][i] = 0;
	}
	vector<tuple<int, int, int> > briaunos;
	for(int i=0; i<M; i++)
	{
		ll a, b, w;
		cin >> a >> b >> w;
		briaunos.push_back(make_tuple(w, a, b));
	}
	sort(briaunos.begin(), briaunos.end());
	M = min(401, M);
	vector<int> virsunes;
	for(int i=0; i<M; i++)
	{
		virsunes.push_back(get<1>(briaunos[i]));
		virsunes.push_back(get<2>(briaunos[i]));
	}
	sort(virsunes.begin(), virsunes.end());
	virsunes.erase(unique(virsunes.begin(), virsunes.end()), virsunes.end());
	map<int, int> mapas;
	N = virsunes.size();
	if(N>500)
	{
		cout << N << " " << M << endl;
	}
	for(int i=0; i<N; i++)
	{
		mapas[virsunes[i]] = i;
	}
	for(int i=0; i<M; i++)
	{
		int a = mapas[get<1>(briaunos[i])];
		int b = mapas[get<2>(briaunos[i])];
		int w = get<0>(briaunos[i]);
		briaunos[i] = make_tuple(w, a, b);
		atstumas[a][b] = w;
		atstumas[b][a] = w;
	}
	//for(int i=0; i<M; i++)
	//	cout << get<0>(briaunos[i]) << " " << get<1>(briaunos[i]) << " " << get<2>(briaunos[i]) << endl;
	for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
		{
			for(int k=0; k<N; k++)
			{
				atstumas[j][k] = min(atstumas[j][k], atstumas[k][i] + atstumas[i][j]);
				atstumas[k][j] = min(atstumas[k][j], atstumas[k][i] + atstumas[i][j]);
			}
		}
	}
	/*for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
			cout << atstumas[i][j] << " ";
		cout << endl;
	}*/
	vector<ll> ats;
	for(int i=0; i<N; i++)
	{
		for(int j=i+1; j<N; j++)
			ats.push_back(atstumas[i][j]);
	}
	sort(ats.begin(), ats.end());
	//for(int i=0; i<ats.size(); i++)
	//	cout << ats[i] << " ";
	//cout << endl << ats.size() << endl << k << endl;
	cout << ats[k-1];
	return 0;
}


/*input
7 15 18
2 6 3
5 7 4
6 5 4
3 6 9
6 7 7
1 6 4
7 1 6
7 2 1
4 3 2
3 2 8
5 3 6
2 5 5
3 7 9
4 1 8
2 1 1
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	//ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	int N, N1, M, k;
	cin >> N1 >> M >> k;
	N = N1;
	const ll INF = 1e16;
	for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
			atstumas[i][j] = INF;
		atstumas[i][i] = 0;
	}
	vector<tuple<int, int, int> > briaunos;
	for(int i=0; i<M; i++)
	{
		ll a, b, w;
		cin >> a >> b >> w;
		briaunos.push_back(make_tuple(w, a, b));
	}
	sort(briaunos.begin(), briaunos.end());
	M = min(401, M);
	vector<int> virsunes;
	for(int i=0; i<M; i++)
	{
		virsunes.push_back(get<1>(briaunos[i]));
		virsunes.push_back(get<2>(briaunos[i]));
	}
	sort(virsunes.begin(), virsunes.end());
	virsunes.erase(unique(virsunes.begin(), virsunes.end()), virsunes.end());
	map<int, int> mapas;
	N = virsunes.size();
	/*if(N>500)
	{
		cout << N << " " << M << endl;
	}*/
	for(int i=0; i<N; i++)
	{
		mapas[virsunes[i]] = i;
	}
	ll atstumas[N][N];

	for(int i=0; i<M; i++)
	{
		int a = mapas[get<1>(briaunos[i])];
		int b = mapas[get<2>(briaunos[i])];
		int w = get<0>(briaunos[i]);
		briaunos[i] = make_tuple(w, a, b);
		atstumas[a][b] = w;
		atstumas[b][a] = w;
	}
	//for(int i=0; i<M; i++)
	//	cout << get<0>(briaunos[i]) << " " << get<1>(briaunos[i]) << " " << get<2>(briaunos[i]) << endl;

	for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
		{
			for(int k=j+1; k<N; k++)
			{
				atstumas[j][k] = min(atstumas[j][k], atstumas[k][i] + atstumas[i][j]);
				atstumas[k][j] = min(atstumas[k][j], atstumas[k][i] + atstumas[i][j]);
			}
		}
	}
	/*for(int i=0; i<N; i++)
	{
		for(int j=0; j<N; j++)
			cout << atstumas[i][j] << " ";
		cout << endl;
	}*/
	vector<ll> ats;
	for(int i=0; i<N; i++)
	{
		for(int j=i+1; j<N; j++)
			ats.push_back(atstumas[i][j]);
	}
	sort(ats.begin(), ats.end());
	//for(int i=0; i<ats.size(); i++)
	//	cout << ats[i] << " ";
	//cout << endl << ats.size() << endl << k << endl;
	cout << ats[k-1];
	return 0;
}


using System;
using System.Linq;

namespace codeforces
{

    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            int[] rez = new int[count];
            for (int i = 0; i < count; i++)
            {
                int[] hm = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (hm[0] % hm[1] == 0)
                    rez[i] = hm[0] ;
                else if (hm[0] < hm[1])
                    rez[i] = 0;
                else
                {
                    int c = hm[0] - hm[1]/2;
                    rez[i] = hm[1]/2+(c / hm[1])*hm[1];
                }
            }
            foreach (int c in rez)
                Console.WriteLine(c);

        }
    }
}


using System;
using System.Linq;

namespace codeforces
{

    class Program
    {
        static void Main(string[] args)
        {

            long count = int.Parse(Console.ReadLine());
            long[] rez = new long[count];
            for (int i = 0; i < count; i++)
            {
                long[] hm = Console.ReadLine().Split().Select(long.Parse).ToArray();
                if (hm[0] % hm[1] == 0)
                    rez[i] = hm[0] / hm[1];
                else if (hm[0] < hm[1])
                    rez[i] = 0;
                else
                {
                    long c = hm[0] - hm[1]/2;
                    rez[i] = hm[1]/2+(c / hm[1])*hm[1];
                }
            }
            foreach (long c in rez)
                Console.WriteLine(c);

        }
    }
}


using System;
using System.Linq;

namespace codeforces
{

    class Program
    {
        static void Main(string[] args)
        {

            long count = int.Parse(Console.ReadLine());
            long[] rez = new long[count];
            for (int i = 0; i < count; i++)
            {
                long[] hm = Console.ReadLine().Split().Select(long.Parse).ToArray();
                if (hm[0] % hm[1] == 0)
                    rez[i] = hm[0];
                else if (hm[0] < hm[1])
                    rez[i] = 0;
                else
                {
                    long c = hm[0] - hm[1]/2;
                    rez[i] = hm[1]/2+(c / hm[1])*hm[1];
                }
            }
            foreach (long c in rez)
                Console.WriteLine(c);

        }
    }
}


using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace cf611
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_cf611B();
        }

        public static void solve_cf611B()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int tt = 0; tt < t; tt++)
            {
                int[] nk = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                int n = nk[0];
                int k = nk[1];
                int lim = k / 2;
                int r = n % k;
                int ans = 0;
                if (r > lim)
                {
                    ans = lim;
                }
                else
                {
                    ans = r;
                }
                Console.WriteLine(k * (n / k) + ans);
            }
        }

        public static void solve_cf611A()
        {
            int t = Convert.ToInt32(Console.ReadLine());
            for (int tt = 0; tt < t; tt++)
            {
                int[] hm = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
                Console.WriteLine(Math.Abs(1440 - ((hm[0] * 60) + hm[1])));
            }
        }
    }
}


using System;
using System.Text;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int t = sc.NextInt();
        var sb = new StringBuilder();
        for (int i = 0; i < t; i++)
        {
            sb.AppendLine(Q(sc.NextInt(), sc.NextInt()));
        }

        Console.Write(sb.ToString());
    }

    private string Q(int n, int k)
    {
        /*
         * nキャンディー
         * k子供
         *
         * 最大キャンディ b min a
         * b-a <= 1
         * floor(K/2) を超えない a+1持ってる子供
         */

        // 使うキャンディーの最大数

        int d = n / k;
        int m = n % k;

        // b持ってるの k/2

        if (m <= k / 2)
        {
            return n.ToString();
        }
        else
        {
            return (d * k + (k / 2)).ToString();
        }
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}


using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;

namespace dhsmfeh_zhelddmf_gkqslek
{
    class Priority_queue<T>
    {
        static List<int> pq;
        public Priority_queue()
        {
            pq = new List<int>();
        }

        public void push(int num)
        {
            int idx = -1;

            if (pq.Count == 0)
            {
                pq.Add(num);
                return;
            }

            for (int i = pq.Count; --i > -1;)
            {
                if (pq[i] < num)
                {
                    idx = i + 1;
                    break;
                }
            }

            if (idx == -1) { idx = 0; }
            pq.Insert(idx, num);
        }

        public int pop(int num)
        {
            int answer = pq[num];
            pq.RemoveAt(num);
            return answer;
        }

        public int count
        {
            get
            {
                return pq.Count;
            }
        }
    }
    class Program
    {
        static StringBuilder sb = new StringBuilder();
        static void Main(string[] args)
        {
            int loop = int.Parse(Console.ReadLine());

            for(int i = 0; i<loop; i++)
            {
                int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();

                int answer = (arr[0] / arr[1]) * arr[1];
                int foo = Math.Min(arr[1] / 2, arr[0] - answer);

                sb.Append(answer + foo + "\n");
            }

            Console.Write(sb.ToString());
        }
    }
}


using System;

namespace PracticeCodeForces
{
    class Program
    {
        public static int MaxCandyToGive(int candies, int kids)
        {
            int MaxCandy = 0;
            int candyLeft = 0;
            int Qoutient = candies/kids;
            int remainder = candies % kids;
            if (remainder == 0)
            {
                MaxCandy = candies;
            }
            else {
                candyLeft = remainder - (kids / 2);
                MaxCandy = candies - candyLeft;
            }
            return MaxCandy;
        }
        static void Main(string[] args)
        {
            int cases = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i<cases; ++i)
            {
                string Line = Console.ReadLine();
                string[] paramList = Line.Split(' ');
                Console.WriteLine(MaxCandyToGive(Convert.ToInt32(paramList[0]), Convert.ToInt32(paramList[1])));
            }
        }
    }
}


using System;

namespace PracticeCodeForces
{
    class Program
    {
        public static int MaxCandyToGive(int candies, int kids)
        {
            int MaxCandy = 0;
            int candyLeft = 0;
            //int Qoutient = candies / kids;
            int remainder = candies % kids;
            int halfKids = kids / 2;
            if (candies < kids)
            {
                if (candies <= halfKids)
                {
                    MaxCandy = candies;
                }
                else
                {
                    MaxCandy = halfKids;
                }
            }
            else
            {
                if (remainder == 0)
                {
                    MaxCandy = candies;
                }
                else
                {
                    candyLeft = halfKids>remainder ? 0: remainder - halfKids;
                    MaxCandy = candies - candyLeft;
                }
            }

            return MaxCandy;
        }
        static void Main(string[] args)
        {
            int cases = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i<cases; i++)
            {
                string Line = Console.ReadLine();
                string[] paramList = Line.Split(' ');
                Console.WriteLine(MaxCandyToGive(Convert.ToInt32(paramList[0]), Convert.ToInt32(paramList[1])));
            }
        }
    }
}


using System;

namespace PracticeCodeForces
{
    class Program
    {
        public static int MaxCandyToGive(int candies, int kids)
        {
            int MaxCandy = 0;
            int candyLeft = 0;
             if (kids != 0)
            {
                int Qoutient = candies / kids;
                int remainder = candies % kids;
                int halfKids = kids / 2;
                if (candies < kids)
                {
                    if (candies <= halfKids)
                    {
                        MaxCandy = candies;
                    }
                    else
                    {
                        MaxCandy = halfKids;
                    }
                }
                else
                {
                    if (remainder == 0)
                    {
                        MaxCandy = candies;
                    }
                    else
                    {
                        candyLeft = remainder - halfKids;
                        MaxCandy = candies - candyLeft;
                    }
                }
            }
            else { MaxCandy = 0; }

            return MaxCandy;
        }
        static void Main(string[] args)
        {
            int cases = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i<cases; ++i)
            {
                string Line = Console.ReadLine();
                string[] paramList = Line.Split(' ');
                Console.WriteLine(MaxCandyToGive(Convert.ToInt32(paramList[0]), Convert.ToInt32(paramList[1])));
            }
        }
    }
}


using System;

namespace PracticeCodeForces
{
    class Program
    {
        public static int MaxCandyToGive(int candies, int kids)
        {
            int MaxCandy = 0;
            int candyLeft = 0;
            //int Qoutient = candies / kids;
            int remainder = candies % kids;
            int halfKids = kids / 2;
            if (candies < kids)
            {
                if (candies <= halfKids)
                {
                    MaxCandy = candies;
                }
                else
                {
                    MaxCandy = halfKids;
                }
            }
            else
            {
                if (remainder == 0)
                {
                    MaxCandy = candies;
                }
                else
                {
                    candyLeft = remainder - halfKids;
                    MaxCandy = candies - candyLeft;
                }
            }

            return MaxCandy;
        }
        static void Main(string[] args)
        {
            int cases = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i<cases; i++)
            {
                string Line = Console.ReadLine();
                string[] paramList = Line.Split(' ');
                Console.WriteLine(MaxCandyToGive(Convert.ToInt32(paramList[0]), Convert.ToInt32(paramList[1])));
            }
        }
    }
}


using System;

namespace PracticeCodeForces
{
    class Program
    {
        public static int MaxCandyToGive(int candies, int kids)
        {
            int MaxCandy = 0;
            int candyLeft = 0;
            if (kids != 0)
            {
                int Qoutient = candies / kids;
                int remainder = candies % kids;
                int halfKids = kids / 2;
                if (candies < kids)
                {
                    if (candies <= halfKids)
                    {
                        MaxCandy = candies;
                    }
                    else
                    {
                        MaxCandy = halfKids;
                    }
                }
                if (remainder == 0)
                {
                    MaxCandy = candies;
                }
                else
                {
                    candyLeft = remainder - halfKids;
                    MaxCandy = candies - candyLeft;
                }
            }
            else { MaxCandy = 0; }

            return MaxCandy;
        }
        static void Main(string[] args)
        {
            int cases = Convert.ToInt32(Console.ReadLine());
            for (int i = 0; i<cases; ++i)
            {
                string Line = Console.ReadLine();
                string[] paramList = Line.Split(' ');
                Console.WriteLine(MaxCandyToGive(Convert.ToInt32(paramList[0]), Convert.ToInt32(paramList[1])));
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int TEST_NUM = int.Parse(Console.ReadLine().Trim());
            for (int theTest = 0; theTest < TEST_NUM; theTest++)
            {
                int[] data = Array.ConvertAll(Console.ReadLine().Trim().Split(), int.Parse);
                int N_candies = data[0];
                int K_children = data[1];
                int mod = N_candies % K_children;
                if (2 * mod <= K_children)
                {
                    Console.WriteLine(N_candies);
                }
                else
                {
                    int delta = mod - (K_children / 2);
                    Console.WriteLine(N_candies - delta);
                }
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using static System.Array;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var t = input.ReadInt();
      var ans = new int[t];
      for (int i = 0; i < t; i++)
      {
        var (n, k) = input.Read2Int();
        ans[i] = k * (n / k);
        n %= k;
        ans[i] += Min(k / 2, n);
      }
      Write(string.Join(Environment.NewLine, ans));
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private readonly TextReader reader;

    public string ReadToEnd()
    {
      return reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWs();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = reader.Read();
        if (c == -1)
          throw new EndOfStreamException("Digit expected, but end of stream occurs");
      }

      if (!char.IsDigit((char)c))
        throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");

      checked
      {
        var result = (char)c - '0';
        c = reader.Read();
        while (c > 0 && !char.IsWhiteSpace((char)c))
        {
          if (!char.IsDigit((char)c))
            throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
          result = result * 10 + (char)c - '0';
          c = reader.Read();
        }

        if (isNegative)
          result = -result;
        return result;
      }
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public (int, int) Read2Int() =>
      (ReadInt(), ReadInt());

    public (int, int, int) Read3Int() =>
      (ReadInt(), ReadInt(), ReadInt());

    public (int, int, int, int) Read4Int() =>
      (ReadInt(), ReadInt(), ReadInt(), ReadInt());

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWs();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = reader.Read();
      }

      return sb.ToString();
    }

    private int SkipWs()
    {
      var c = reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main()
    {
      var solver = new ProblemSolver(In);
      solver.Solve();
    }
  }

  #endregion
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using static System.Array;
using static System.Console;
using static System.Math;

namespace Olymp
{
  public class ProblemSolver
  {
    private readonly Tokenizer input;

    public void Solve()
    {
      var t = input.ReadInt();
      for (int i = 0; i < t; i++)
      {
        var (n, k) = input.Read2Int();
        var ans = k * (n / k);
        n %= k;
        ans += Min(k / 2, n);
        WriteLine(ans);
      }
    }

    public ProblemSolver(TextReader input)
    {
      this.input = new Tokenizer(input);
    }
  }

  #region Service classes

  public class Tokenizer
  {
    private readonly TextReader reader;

    public string ReadToEnd()
    {
      return reader.ReadToEnd();
    }

    public int ReadInt()
    {
      var c = SkipWs();
      if (c == -1)
        throw new EndOfStreamException();
      var isNegative = false;
      if (c == '-' || c == '+')
      {
        isNegative = c == '-';
        c = reader.Read();
        if (c == -1)
          throw new EndOfStreamException("Digit expected, but end of stream occurs");
      }

      if (!char.IsDigit((char)c))
        throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");

      checked
      {
        var result = (char)c - '0';
        c = reader.Read();
        while (c > 0 && !char.IsWhiteSpace((char)c))
        {
          if (!char.IsDigit((char)c))
            throw new InvalidOperationException($"Digit expected, but was: '{(char)c}'");
          result = result * 10 + (char)c - '0';
          c = reader.Read();
        }

        if (isNegative)
          result = -result;
        return result;
      }
    }

    public string ReadLine()
    {
      return reader.ReadLine();
    }

    public long ReadLong()
    {
      return long.Parse(ReadToken());
    }

    public double ReadDouble()
    {
      return double.Parse(ReadToken(), CultureInfo.InvariantCulture);
    }

    public int[] ReadIntArray(int n)
    {
      var a = new int[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadInt();
      return a;
    }

    public (int, int) Read2Int() =>
      (ReadInt(), ReadInt());

    public (int, int, int) Read3Int() =>
      (ReadInt(), ReadInt(), ReadInt());

    public (int, int, int, int) Read4Int() =>
      (ReadInt(), ReadInt(), ReadInt(), ReadInt());

    public long[] ReadLongArray(int n)
    {
      var a = new long[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadLong();
      return a;
    }

    public double[] ReadDoubleArray(int n)
    {
      var a = new double[n];
      for (var i = 0; i < n; i++)
        a[i] = ReadDouble();
      return a;
    }

    public string ReadToken()
    {
      var c = SkipWs();
      if (c == -1)
        return null;
      var sb = new StringBuilder();
      while (c > 0 && !char.IsWhiteSpace((char)c))
      {
        sb.Append((char)c);
        c = reader.Read();
      }

      return sb.ToString();
    }

    private int SkipWs()
    {
      var c = reader.Read();
      if (c == -1)
        return c;
      while (c > 0 && char.IsWhiteSpace((char)c))
        c = reader.Read();
      return c;
    }

    public Tokenizer(TextReader reader)
    {
      this.reader = reader;
    }
  }

  internal class Program
  {
    public static void Main()
    {
      var solver = new ProblemSolver(In);
      solver.Solve();
    }
  }

  #endregion
}


using System;
using static System.Console;
using static System.Math;
using static System.Array;

namespace ConsoleApp9
{
    class Program
    {
        static void Conv(string[] a,int[] b)
        {
            for(int i = 0; i < a.Length; i++)
            {
                b[i] = Convert.ToInt32(a[i]);
            }
        }
        static void Print(int[] b)
        {
            for(int i = 0; i < b.Length; i++)
            {
                Write($"{b[i]} ");
            }
            WriteLine();
        }
        static int Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            for (int i = 0; i < n; i++)
            {
                string[] a = ReadLine().Split(' ');
                int b = Convert.ToInt32(a[0]), c = Convert.ToInt32(a[1]);
                int summ = b / c * c;
                if (b - summ > c / 2)
                    summ += c / 2;
                else summ += b - summ;
                WriteLine(summ);
            }
            return 0;
        }

    }
}


using System;
using System.Linq;

namespace Siri5
{
    class Program
    {
        static void Main(string[] args)
        {
            int AR = int.Parse(Console.ReadLine());
            for (int i = 0; i < AR; i++)
            {
                var d = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                int n = Convert.ToInt32(d[0]);
                int k = Convert.ToInt32(d[1]);

                int END = 0;
                int p = n / k;
                int pp = p * k;
                int ppn = n - pp;
                if (ppn > k/2)
                {
                    END = pp + k / 2;
                }
                else
                {
                    END = pp + ppn;
                }
                Console.WriteLine(END);
            }
        }
    }
}


using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
	class Program
	{
		static void Main()
		{
			var t = int.Parse(Console.ReadLine());

			var results = new List<string>();
			for (var i = 0; i < t; i++)
			{
				var line = Console.ReadLine().Split(' ');
				var n = int.Parse(line[0]);
				var k = int.Parse(line[1]);

				var a = n / k;
				var mod = n - a * k;

				if (mod > k / 2 - 1)
					mod -= k / 2;

				results.Add((n - mod).ToString());

			}

			foreach (var result in results)
			{
				Console.WriteLine(result);
			}
		}
	}

}


using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
	class Program
	{
		static void Main()
		{
			var t = int.Parse(Console.ReadLine());

			var results = new List<string>();
			for (var i = 0; i < t; i++)
			{
				var line = Console.ReadLine().Split(' ');
				var n = int.Parse(line[0]);
				var k = int.Parse(line[1]);

				var a = n / k;
				var mod = n - a * k;

				if (mod > k / 2)
					n -= mod - k / 2;

				results.Add(n.ToString());

			}

			foreach (var result in results)
			{
				Console.WriteLine(result);
			}
		}
	}

}


using System;
namespace R611D3B
{
    class Program
    {
        static void Main(string[] args)
        {
            int t;
            t = int.Parse(Console.ReadLine());
            for (int i = 0; i < t; i++)
            {
                var line = Console.ReadLine().Split(' ');
                if (line == null) { break; }

                var n = int.Parse(line[0]);
                var k = int.Parse(line[1]);

                var ans = n / k * k + Math.Min(n % k, k / 2);
                Console.WriteLine(ans);
            }
        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            bool f=false;
            for (int i=0;i<n;i++)
            {
                 string[]y=Console.ReadLine().Split(' ');

                 int a=int.Parse(y[0]);
                 int b=int.Parse(y[1]);
                 int c=a/b;
                 int sum=c*b;
                 sum+=Math.Min(b/2,a%b);
                 Console.WriteLine(sum);
            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text;
using static Template;
using static System.Console;
using static System.Convert;
using static System.Math;
using Pi = Pair<int, int>;

class Solver
{
    public void Solve(Scanner sc)
    {
        var t = sc.Int;
        while (t-- > 0)
        {
            int n, k;
            sc.Make(out n, out k);
            WriteLine(n / k * k + Min(n % k, k / 2));
        }
    }
}

#region Template
public class Template
{
    static void Main(string[] args)
    {
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
        new Solver().Solve(new Scanner());
        Console.Out.Flush();
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmin<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == 1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static bool chmax<T>(ref T a, T b) where T : IComparable<T>
    { if (a.CompareTo(b) == -1) { a = b; return true; } return false; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static void swap<T>(ref T a, ref T b)
    { var t = b; b = a; a = t; }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f();
        return rt;
    }
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public static T[] Create<T>(int n, Func<int, T> f)
    {
        var rt = new T[n];
        for (var i = 0; i < rt.Length; ++i)
            rt[i] = f(i);
        return rt;
    }
    public static void Fail<T>(T s) { Console.WriteLine(s); Console.Out.Close(); Environment.Exit(0); }
}

public class Scanner
{
    public string Str => ReadLine().Trim();
    public int Int => int.Parse(Str);
    public long Long => long.Parse(Str);
    public double Double => double.Parse(Str);
    public int[] ArrInt => Str.Split(' ').Select(int.Parse).ToArray();
    public long[] ArrLong => Str.Split(' ').Select(long.Parse).ToArray();
    public char[][] Grid(int n) => Create(n, () => Str.ToCharArray());
    public int[] ArrInt1D(int n) => Create(n, () => Int);
    public long[] ArrLong1D(int n) => Create(n, () => Long);
    public int[][] ArrInt2D(int n) => Create(n, () => ArrInt);
    public long[][] ArrLong2D(int n) => Create(n, () => ArrLong);
    public Pair<T1, T2> PairMake<T1, T2>() => new Pair<T1, T2>(Next<T1>(), Next<T2>());
    public Pair<T1, T2, T3> PairMake<T1, T2, T3>() => new Pair<T1, T2, T3>(Next<T1>(), Next<T2>(), Next<T3>());
    private Queue<string> q = new Queue<string>();
    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public T Next<T>() { if (q.Count == 0) foreach (var item in Str.Split(' ')) q.Enqueue(item); return (T)Convert.ChangeType(q.Dequeue(), typeof(T)); }
    public void Make<T1>(out T1 v1) => v1 = Next<T1>();
    public void Make<T1, T2>(out T1 v1, out T2 v2) { v1 = Next<T1>(); v2 = Next<T2>(); }
    public void Make<T1, T2, T3>(out T1 v1, out T2 v2, out T3 v3) { Make(out v1, out v2); v3 = Next<T3>(); }
    public void Make<T1, T2, T3, T4>(out T1 v1, out T2 v2, out T3 v3, out T4 v4) { Make(out v1, out v2, out v3); v4 = Next<T4>(); }
    public void Make<T1, T2, T3, T4, T5>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5) { Make(out v1, out v2, out v3, out v4); v5 = Next<T5>(); }
    public void Make<T1, T2, T3, T4, T5, T6>(out T1 v1, out T2 v2, out T3 v3, out T4 v4, out T5 v5, out T6 v6) { Make(out v1, out v2, out v3, out v4, out v5); v6 = Next<T6>(); }
}

public class Pair<T1, T2> : IComparable<Pair<T1, T2>>
{
    public T1 v1;
    public T2 v2;
    public Pair() { }
    public Pair(T1 v1, T2 v2)
    { this.v1 = v1; this.v2 = v2; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2> p)
    {
        var c = Comparer<T1>.Default.Compare(v1, p.v1);
        if (c == 0)
            c = Comparer<T2>.Default.Compare(v2, p.v2);
        return c;
    }
    public override string ToString() => $"{v1.ToString()} {v2.ToString()}";
    public void Tie(out T1 a, out T2 b) { a = v1; b = v2; }
}

public class Pair<T1, T2, T3> : Pair<T1, T2>, IComparable<Pair<T1, T2, T3>>
{
    public T3 v3;
    public Pair() : base() { }
    public Pair(T1 v1, T2 v2, T3 v3) : base(v1, v2)
    { this.v3 = v3; }

    [MethodImpl(MethodImplOptions.AggressiveInlining)]
    public int CompareTo(Pair<T1, T2, T3> p)
    {
        var c = base.CompareTo(p);
        if (c == 0)
            c = Comparer<T3>.Default.Compare(v3, p.v3);
        return c;
    }
    public override string ToString() => $"{base.ToString()} {v3.ToString()}";
    public void Tie(out T1 a, out T2 b, out T3 c) { Tie(out a, out b); c = v3; }
}
#endregion


using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        int t = int.Parse(Console.ReadLine());
        for (int i = 0; i < t; i++)
        {
            Solve();
        }
    }
    static void Solve()
    {
        var hw = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = hw[0];
        var k = hw[1];
        Console.WriteLine(Min((n / k) * k + k / 2, n));
    }
}


using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        int t = int.Parse(Console.ReadLine());
        for (int i = 0; i < t; i++)
        {
            Solve();
        }
    }
    static void Solve()
    {
        var hw = Console.ReadLine().Split().Select(long.Parse).ToArray();
        var n = hw[0];
        var k = hw[1];
        Console.WriteLine(Min((n / k) * k + k / 2, n));
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication36
{
    class Program
    {
        //int[] arr = Console.ReadLine().Split().Select(E => int.Parse(E)).ToArray();
        //int n = int.Parse(Console.ReadLine());

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                long z=0;
                long[] arr = Console.ReadLine().Split().Select(E => long.Parse(E)).ToArray();
                long c = arr[0];
                long k = arr[1];

                if (c / k > 0)
                {
                    z+=((c/k)*k);
                }
                if (c % k >= (k / 2)-1)
                {
                    if (c % k >= (k / 2))
                    {
                        z += (k / 2);
                    }
                    else { z += (k / 2) - 1; }

                }
                else { z += c % k; }
                Console.WriteLine(z);

            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication36
{
    class Program
    {
        //int[] arr = Console.ReadLine().Split().Select(E => int.Parse(E)).ToArray();
        //int n = int.Parse(Console.ReadLine());

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                int z=0;
                int[] arr = Console.ReadLine().Split().Select(E => int.Parse(E)).ToArray();
                int c = arr[0];
                int k = arr[1];

                if (c / k > 0)
                {
                    z+=((c/k)*k);
                }
                if (c % k >= k / 2)
                {
                    z +=( k / 2);
                }
                Console.WriteLine(z);

            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication36
{
    class Program
    {
        //int[] arr = Console.ReadLine().Split().Select(E => int.Parse(E)).ToArray();
        //int n = int.Parse(Console.ReadLine());

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                int z=0;
                int[] arr = Console.ReadLine().Split().Select(E => int.Parse(E)).ToArray();
                int c = arr[0];
                int k = arr[1];

                if (c / k > 0)
                {
                    z+=((c/k)*k);
                }
                if (c % k >= (k / 2)-1)
                {
                    if (c % k >= (k / 2))
                    {
                        z += (k / 2);
                    }
                    else { z += (k / 2) - 1; }

                }
                Console.WriteLine(z);

            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication36
{
    class Program
    {
        //int[] arr = Console.ReadLine().Split().Select(E => int.Parse(E)).ToArray();
        //int n = int.Parse(Console.ReadLine());

        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            for (int i = 0; i < n; i++)
            {
                long z=0;
                long[] arr = Console.ReadLine().Split().Select(E => long.Parse(E)).ToArray();
                long c = arr[0];
                long k = arr[1];

                if (c / k > 0)
                {
                    z+=((c/k)*k);
                }
                if (c % k >= (k / 2)-1)
                {
                    if (c % k >= (k / 2))
                    {
                        z += (k / 2);
                    }
                    else { z += (k / 2) - 1; }

                }
                Console.WriteLine(z);

            }

        }
    }
}


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace Codeforces.NET
{
    class Program
    {

        static void Main(string[] args)
        {
            int t = int.Parse(Console.ReadLine());
            for (int i = 0; i < t; i++)
            {
                int[] parts = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                int n = parts[0];
                int k = parts[1];

                int howMany = n / k;
                int rest = n % k;

                int solution = k * howMany;

                if (rest <= k/2)
                {
                    solution += rest;
                }
                else
                {
                    solution += k / 2;
                }

                Console.WriteLine(solution);
            }
            Console.ReadLine();
        }
    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;

namespace HW1
{

    public class Program
    {

        static void swap(List<int> arr, int i, int j)
        {
            int temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
        }

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());

            for (int z = 0; z < n; z++)
            {
                int[] nk = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

                double half = Math.Floor((double)nk[1]/2);

                if (nk[0] >= nk[1])
                {
                    int each = nk[0] / nk[1];
                    int r = nk[0] % nk[1];

                    if (r <= 1)
                    {
                        Console.WriteLine(nk[0]);
                        continue;
                    }
                    else
                    {
                        int s = each * nk[1];
                        for (int i = 0; i < half && s <= nk[0]; i++)
                        {
                            s++;
                        }

                        Console.WriteLine(s);
                    }
                }
                else
                {

                    Console.WriteLine(half);

                }

            }

            return;
        }

    }
}


using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net.WebSockets;

namespace HW1
{

    public class Program
    {

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());

            for (int z = 0; z < n; z++)
            {
                int[] nk = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

                double half = Math.Floor((double)nk[1]/2);

                if (nk[0] >= nk[1])
                {
                    long each = nk[0] / nk[1];
                    int r = nk[0] % nk[1];

                    if (r <= 1)
                    {
                        Console.WriteLine(nk[0]);
                        continue;
                    }
                    else
                    {
                        long s = each * nk[1];
                        s += (half < nk[0] - s) ? (int)half : nk[0];
                        Console.WriteLine(s);
                    }
                }
                else
                {

                    Console.WriteLine(half <= nk[0] ? half : nk[0]);

                }

            }

            return;
        }


using System;

namespace HW1
{

    public class Program
    {

        static void Main(string[] args)
        {

            int n = Convert.ToInt32(Console.ReadLine());

            for (int z = 0; z < n; z++)
            {
                int[] nk = Array.ConvertAll<string, int>(Console.ReadLine().Split(' '), int.Parse);

                double half = Math.Floor((double)nk[1]/2);

                if (nk[0] >= nk[1])
                {
                    long each = nk[0] / nk[1];
                    int r = nk[0] % nk[1];

                    if (r <= 1)
                    {
                        Console.WriteLine(nk[0]);
                        continue;
                    }
                    else
                    {
                        long s = each * nk[1];
                        for (int i = 1; i <= half && s < nk[0]; i++)
                        {
                            s++;
                        }

                        Console.WriteLine(s);
                    }
                }
                else
                {

                    Console.WriteLine(half <= nk[0] ? half : nk[0]);

                }

            }

            return;
        }

    }
}