#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;

const int maxN = 200500;

const ld PI = acos(-1.0);
const ld acos0 = acos(0.0);
const ld acos02 = acos(0.0) + PI / 2;
const ld acos03 = acos(0.0) + PI;

int n, r, v;

bool can(ld sf, ld c) {
    ld t = (acos0 * r / v) + c / 2;
    ld tmp = r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v;
    t = (acos02 * r / v) + c / 2;
    tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    t = (acos03 * r / v) + c / 2;
    tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    return tmp >= sf;
}

double solve(ld sf) {
    ld l = sf - 10, r = sf + 10;

    int it = 40;

    while (it--) {
        ld mid = (l + r) / 2;
        if (can(sf, mid)) r = mid;
        else l = mid;
    }
    can(sf, l);
    //can(sf, 3.849644710502);
    return l;
}

int main() {
    //freopen("input.txt", "r", stdin);

    scanf("%d%d%d", &n, &r, &v);

    while (n--) {
        double s, f;
        scanf("%lf%lf", &s, &f);
        printf("%.10f\n", solve(f - s));
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;

const int maxN = 200500;

const ld PI = acos(-1.0);
const ld acos0 = acos(0.0);
const ld acos02 = acos(0.0) + PI;

int n, r, v;

bool can(ld sf, ld c) {
    ld t = (acos0 * r / v) + c / 2;
    ld tmp = r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v;
    t = (acos02 * r / v) + c / 2;
    tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    //t = (acos03 * r / v) + c / 2;
    //tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    return tmp >= sf;
}

double solve(ld sf) {
    ld l = 0, r = sf + 10;

    int it = 60;

    while (fabs(r - l) / max<double>(max(l, r), 1) > 1e-6) {
        ld mid = (l + r) / 2;
        if (can(sf, mid)) r = mid;
        else l = mid;
    }
    can(sf, l);
    //can(sf, 3.849644710502);
    return l;
}

int main() {
    //freopen("input.txt", "r", stdin);

    scanf("%d%d%d", &n, &r, &v);

    while (n--) {
        double s, f;
        scanf("%lf%lf", &s, &f);
        printf("%.10f\n", solve(f - s));
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;

const int maxN = 200500;

const ld PI = acos(-1.0);
const ld acos0 = acos(0.0);
const ld acos02 = acos(0.0) + PI;

int n, r, v;

bool can(ld sf, ld c) {
    ld t = (acos0 * r / v) + c / 2;
    ld tmp = r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v;
    t = (acos02 * r / v) + c / 2;
    tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    //t = (acos03 * r / v) + c / 2;
    //tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    return tmp >= sf;
}

double solve(ld sf) {
    ld l = 0, r = sf + 10;

    int it = 60;

    while (fabs(r - l) > 1e-9) {
        ld mid = (l + r) / 2;
        if (can(sf, mid)) r = mid;
        else l = mid;
    }
    can(sf, l);
    //can(sf, 3.849644710502);
    return l;
}

int main() {
    //freopen("input.txt", "r", stdin);

    scanf("%d%d%d", &n, &r, &v);

    while (n--) {
        double s, f;
        scanf("%lf%lf", &s, &f);
        printf("%.10f\n", solve(f - s));
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int maxN = 200500;

const ld PI = acos(-1.0);
const ld acos0 = acos(0.0);
const ld acos02 = acos(0.0) + PI / 2;
const ld acos03 = acos(0.0) + PI;

int n, r, v;

bool can(ld sf, ld c) {
    ld t = (acos0 * r / v) + c / 2;
    ld tmp = r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v;
    t = (acos02 * r / v) + c / 2;
    tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    t = (acos03 * r / v) + c / 2;
    tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    return tmp >= sf;
}

double solve(ld sf) {
    ld l = 0, r = sf + 10;

    int it = 100;

    while (it--) {
        ld mid = (l + r) / 2;
        if (can(sf, mid)) r = mid;
        else l = mid;
    }
    can(sf, l);
    //can(sf, 3.849644710502);
    return l;
}

int main() {
    //freopen("input.txt", "r", stdin);

    scanf("%d%d%d", &n, &r, &v);

    while (n--) {
        double s, f;
        scanf("%lf%lf", &s, &f);
        printf("%.10f\n", solve(f - s));
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;

const int maxN = 200500;

const ld PI = acos(-1.0);
const ld acos0 = acos(0.0);
const ld acos02 = acos(0.0) + PI / 2;
const ld acos03 = acos(0.0) + PI;

int n, r, v;

bool can(ld sf, ld c) {
    ld t = (acos0 * r / v) + c / 2;
    ld tmp = r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v;
    t = (acos02 * r / v) + c / 2;
    tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    t = (acos03 * r / v) + c / 2;
    tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    return tmp >= sf;
}

double solve(ld sf) {
    ld l = 0, r = sf + 10;

    int it = 60;

    while (it--) {
        ld mid = (l + r) / 2;
        if (can(sf, mid)) r = mid;
        else l = mid;
    }
    can(sf, l);
    //can(sf, 3.849644710502);
    return l;
}

int main() {
    //freopen("input.txt", "r", stdin);

    scanf("%d%d%d", &n, &r, &v);

    while (n--) {
        double s, f;
        scanf("%lf%lf", &s, &f);
        printf("%.10f\n", solve(f - s));
    }
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <bitset>
#include <algorithm>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;

const int maxN = 200500;

const ld PI = acos(-1.0);
const ld acos0 = acos(0.0);
const ld acos02 = acos(0.0) + PI;

int n, r, v;

bool can(ld sf, ld c) {
    ld t = (acos0 * r / v) + c / 2;
    ld tmp = r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v;
    t = (acos02 * r / v) + c / 2;
    tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    //t = (acos03 * r / v) + c / 2;
    //tmp = max(tmp, r * (cos(t * v / r) - cos((t - c) * v / r)) + c * v);
    return tmp >= sf;
}

double solve(ld sf) {
    ld l = 0, r = sf + 10;

    int it = 60;

    while (it--) {
        ld mid = (l + r) / 2;
        if (can(sf, mid)) r = mid;
        else l = mid;
    }
    can(sf, l);
    //can(sf, 3.849644710502);
    return l;
}

int main() {
    //freopen("input.txt", "r", stdin);

    scanf("%d%d%d", &n, &r, &v);

    while (n--) {
        double s, f;
        scanf("%lf%lf", &s, &f);
        printf("%.10f\n", solve(f - s));
    }
}


// {{{
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long lint;
typedef pair<int, int> PII;
typedef vector<int> VI;
// }}}

const double EPS = 1e-7;
const double PI = acos(-1.0);

double r, v, s, f;

double gao(double sgn) {
  double low = 0, high = f - s + 2 * PI * r;
  while (high - low > EPS) {
    double mid = (low + high) / 2;
    (mid + r * sgn * sin(mid / r) > (f - s) / 2 ? high : low) = mid;
  }
  return low / v * 2;
}

int main() {
  int n;
  scanf("%d%lf%lf", &n, &r, &v);
  REP (i, n) {
    scanf("%lf%lf", &s, &f);
    printf("%.20f\n", min(gao(1), gao(-1)));
  }
  return 0;
}


// {{{
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long lint;
typedef pair<int, int> PII;
typedef vector<int> VI;
// }}}

const double EPS = 1e-10;
const double PI = acos(-1.0);

double r, v, s, f;

double gao(double sgn) {
  double low = 0, high = f - s + 2 * PI * r;
  while (high - low > EPS) {
    double mid = (low + high) / 2;
    (mid + r * sgn * sin(mid / r) > (f - s) / 2 ? high : low) = mid;
  }
  return low / v * 2;
}

int main() {
  int n;
  scanf("%d%lf%lf", &n, &r, &v);
  REP (i, n) {
    scanf("%lf%lf", &s, &f);
    printf("%.20f\n", min(gao(1), gao(-1)));
  }
  return 0;
}


// {{{
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define MP make_pair
#define PB push_back
#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(n);++i)
typedef long long lint;
typedef pair<int, int> PII;
typedef vector<int> VI;
// }}}

const double EPS = 1e-7;
const double PI = acos(-1.0);

double r, v, s, f;

double gao(double sgn) {
  double low = 0, high = f - s + 2 * PI * r;
  REP (i, 70) {
    double mid = (low + high) / 2;
    (mid + r * sgn * sin(mid / r) > (f - s) / 2 ? high : low) = mid;
  }
  return low / v * 2;
}

int main() {
  int n;
  scanf("%d%lf%lf", &n, &r, &v);
  REP (i, n) {
    scanf("%lf%lf", &s, &f);
    printf("%.20f\n", min(gao(1), gao(-1)));
  }
  return 0;
}


#include <bits/stdc++.h>
const double eps=1e-6;
typedef double db;
int Q,R,v,a,b,len;
db Abs(db x){
	if (x<0) return -x;
	return x;
}
bool chk(db x){
	db t=x/R;
	if (x+2*R*Abs(sin(t/2))>=len) return 1;
	return 0;
}
int main(){
	scanf("%d%d%d",&Q,&R,&v);
	while (Q--){
		scanf("%d%d",&a,&b);
		db l=0,r=b-a,ans=0;
		len=b-a;
		for (int tim=1;tim<=100;tim++){
			db mid=(l+r)/2;
			if (chk(mid)) ans=mid,r=mid;
			else l=mid;
		}
		printf("%.7lf\n",ans/v);
	}
}


#include <bits/stdc++.h>
#define db double
using namespace std;

const db PI = acos(-1);
int n, v, r;

db check(db mid) {
	db t, ret = 0;
	t = PI * r / (2 * v) - mid / 2;
	ret = max(ret, mid * v + r * (cos(t * v / r) - cos(v * (t + mid) / r)));
	t = 3 * PI * r / (2 * v) - mid / 2;
	ret = max(ret, mid * v + r * (cos(t * v / r) - cos(v * (t + mid) / r)));
	return ret;
}

db solve(int len) {
	db l = 0, r = 2e9;
	for (int cnt = 0; cnt <= 80; ++cnt) {
		db mid = (l + r) * 0.5;
		if (check(mid) >= len) r = mid;
		else l = mid;
	}
	return (l + r) * 0.5;
}

int main() {
	scanf("%d%d%d", &n, &r, &v);
	for (int i = 1; i <= n; ++i) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%.15lf\n", solve(r - l));
	}
	return 0;
}


#include <bits/stdc++.h>
#define db double
using namespace std;

const db PI = acos(-1);
int n, v, r;

db check(db mid) {
	db t, ret = 0;
	t = PI * r / (2 * v) - mid / 2;
	ret = max(ret, mid * v + r * (cos(t * v / r) - cos(v * (t + mid) / r)));
	t = 3 * PI * r / (2 * v) - mid / 2;
	ret = max(ret, mid * v + r * (cos(t * v / r) - cos(v * (t + mid) / r)));
	return ret;
}

db solve(int len) {
	db l = 0, r = 1e9 + PI;
	for (int cnt = 0; cnt <= 60; ++cnt) {
		db mid = (l + r) * 0.5;
		if (check(mid) >= len) r = mid;
		else l = mid;
	}
	return (l + r) * 0.5;
}

int main() {
	scanf("%d%d%d", &n, &r, &v);
	for (int i = 1; i <= n; ++i) {
		int l, r;
		scanf("%d%d", &l, &r);
		printf("%.15lf\n", solve(r - l));
	}
	return 0;
}


#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
const double pi = acos(-1);

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    int n;
    cin >> n;
    double r, v;
    cin >> r >> v;
    double w = v / r;
    for (int i = 0; i < n; i++) {
        double s, f;
        cin >> s >> f;
        double d = f - s;
        double diff = d - 2 * pi * r * floor(d / 2 / pi / r);
        diff = 2 * pi * r - diff;
        double start = diff / 2;
        double low = 0, high = 10 * start / v;
        for (int bs = 0; bs < 55; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < start) {
                low = mid;
            } else {
                high = mid;
            }
        }
        double disp = low;
        d += start;
        low = 0, high = 10 * d / v;
        for (int bs = 0; bs < 55; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < d) {
                low = mid;
            } else {
                high = mid;
            }
        }
        cout << low - disp << '\n';
    }
    return 0;
}


#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
const double pi = acos(-1);

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    int n;
    cin >> n;
    double r, v;
    cin >> r >> v;
    double w = v / r;
    for (int i = 0; i < n; i++) {
        double s, f;
        cin >> s >> f;
        double d = f - s;
        double diff = d - 2 * pi * r * floor(d / 2 / pi / r);
        diff = 2 * pi * r - diff;
        double start = diff / 2;
        double low = 0, high = 1e10;
        for (int bs = 0; bs < 60; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < start) {
                low = mid;
            } else {
                high = mid;
            }
        }
        double disp = low;
        d += start;
        low = 0, high = 1e10;
        for (int bs = 0; bs < 60; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < d) {
                low = mid;
            } else {
                high = mid;
            }
        }
        cout << low - disp << '\n';
    }
    return 0;
}


#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
const long double pi = acos(-1);

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    int n;
    cin >> n;
    long double r, v;
    cin >> r >> v;
    long double w = v / r;
    for (int i = 0; i < n; i++) {
        long double s, f;
        cin >> s >> f;
        long double d = f - s;
        long double diff = d - 2 * pi * r * floor(d / 2 / pi / r);
        diff = 2 * pi * r - diff;
        long double start = diff / 2;
        long double low = 0, high = 1e10;
        for (int bs = 0; bs < 60; bs++) {
            long double mid = (low + high) / 2;
            long double travel = r * (w * mid - sin(w * mid));
            if (travel < start) {
                low = mid;
            } else {
                high = mid;
            }
        }
        long double disp = low;
        d += start;
        low = 0, high = 1e10;
        for (int bs = 0; bs < 60; bs++) {
            long double mid = (low + high) / 2;
            long double travel = r * (w * mid - sin(w * mid));
            if (travel < d) {
                low = mid;
            } else {
                high = mid;
            }
        }
        cout << low - disp << '\n';
    }
    return 0;
}


#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
const double pi = acos(-1);

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    int n;
    cin >> n;
    double r, v;
    cin >> r >> v;
    double w = v / r;
    for (int i = 0; i < n; i++) {
        double s, f;
        cin >> s >> f;
        double d = f - s;
        double diff = d - 2 * pi * r * floor(d / 2 / pi / r);
        diff = 2 * pi * r - diff;
        double start = diff / 2;
        double low = 0, high = 1e10;
        for (int bs = 0; bs < 40; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < start) {
                low = mid;
            } else {
                high = mid;
            }
        }
        double disp = low;
        d += start;
        low = 0, high = 1e10;
        for (int bs = 0; bs < 40; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < d) {
                low = mid;
            } else {
                high = mid;
            }
        }
        cout << low - disp << '\n';
    }
    return 0;
}


#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
const long double pi = acos(-1);
const long double eps = 1e-7;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    int n;
    cin >> n;
    long double r, v;
    cin >> r >> v;
    long double w = v / r;
    for (int i = 0; i < n; i++) {
        long double s, f;
        cin >> s >> f;
        long double d = f - s;
        long double diff = d - 2 * pi * r * floor(d / 2 / pi / r);
        diff = 2 * pi * r - diff;
        long double start = diff / 2;
        long double low = 0, high = 1e10;
        while (high - low > eps) {
            long double mid = (low + high) / 2;
            long double travel = r * (w * mid - sin(w * mid));
            if (travel < start) {
                low = mid;
            } else {
                high = mid;
            }
        }
        long double disp = low;
        d += start;
        high = 1e10;
        while (high - low > eps) {
            long double mid = (low + high) / 2;
            long double travel = r * (w * mid - sin(w * mid));
            if (travel < d) {
                low = mid;
            } else {
                high = mid;
            }
        }
        cout << low - disp << '\n';
    }
    return 0;
}


#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
const long double pi = acos(-1);

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    int n;
    cin >> n;
    long double r, v;
    cin >> r >> v;
    long double w = v / r;
    for (int i = 0; i < n; i++) {
        long double s, f;
        cin >> s >> f;
        long double d = f - s;
        long double diff = d - 2 * pi * r * floor(d / 2 / pi / r);
        diff = 2 * pi * r - diff;
        long double start = diff / 2;
        long double low = 0, high = 1e10;
        for (int bs = 0; bs < 60; bs++) {
            long double mid = (low + high) / 2;
            long double travel = r * (w * mid - sin(w * mid));
            if (travel < start) {
                low = mid;
            } else {
                high = mid;
            }
        }
        long double disp = low;
        long double totd = 2 * pi * r * (floor(d / 2 / pi / r) + 1);
        long double overt = totd / v;
        long double res = overt - 2 * disp;
        cout << res << '\n';
    }
    return 0;
}


#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
const double pi = acos(-1);

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    int n;
    cin >> n;
    double r, v;
    cin >> r >> v;
    double w = v / r;
    for (int i = 0; i < n; i++) {
        double s, f;
        cin >> s >> f;
        double d = f - s;
        double diff = d - 2 * pi * r * floor(d / 2 / pi / r);
        diff = 2 * pi * r - diff;
        double start = diff / 2;
        double low = 0, high = 10 * start / v;
        for (int bs = 0; bs < 40; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < start) {
                low = mid;
            } else {
                high = mid;
            }
        }
        double disp = low;
        d += start;
        low = 0, high = 10 * d / v;
        for (int bs = 0; bs < 40; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < d) {
                low = mid;
            } else {
                high = mid;
            }
        }
        cout << low - disp << '\n';
    }
    return 0;
}


#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
const double pi = acos(-1);

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    int n;
    cin >> n;
    double r, v;
    cin >> r >> v;
    double w = v / r;
    for (int i = 0; i < n; i++) {
        double s, f;
        cin >> s >> f;
        double d = f - s;
        double diff = d - 2 * pi * r * floor(d / 2 / pi / r);
        diff = 2 * pi * r - diff;
        double start = diff / 2;
        double low = 0, high = 10 * d / v;
        for (int bs = 0; bs < 40; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < start) {
                low = mid;
            } else {
                high = mid;
            }
        }
        double disp = low;
        d += start;
        low = 0, high = 10 * d / v;
        for (int bs = 0; bs < 40; bs++) {
            double mid = (low + high) / 2;
            double travel = r * (w * mid - sin(w * mid));
            if (travel < d) {
                low = mid;
            } else {
                high = mid;
            }
        }
        cout << low - disp << '\n';
    }
    return 0;
}


#include <cmath>
#include <iomanip>
#include <iostream>
using namespace std;
const long double pi = acos(-1);

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout << fixed << setprecision(9);
    int n;
    cin >> n;
    long double r, v;
    cin >> r >> v;
    long double w = v / r;
    for (int i = 0; i < n; i++) {
        long double s, f;
        cin >> s >> f;
        long double d = f - s;
        long double diff = d - 2 * pi * r * floor(d / 2 / pi / r);
        diff = 2 * pi * r - diff;
        long double start = diff / 2;
        long double low = 0, high = 1e12;
        for (int bs = 0; bs < 80; bs++) {
            long double mid = (low + high) / 2;
            long double travel = r * (w * mid - sin(w * mid));
            if (travel < start) {
                low = mid;
            } else {
                high = mid;
            }
        }
        long double disp = low;
        d += start;
        low = 0, high = 1e12;
        for (int bs = 0; bs < 80; bs++) {
            long double mid = (low + high) / 2;
            long double travel = r * (w * mid - sin(w * mid));
            if (travel < d) {
                low = mid;
            } else {
                high = mid;
            }
        }
        cout << low - disp << '\n';
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

template<class T>inline void Read(T &x)
{
    int f = 1;
    char t = getchar();
    while (t < '0' || t > '9') {
        if (t == '-') f = -1;
        t = getchar();
    }
    x = 0;
    while (t >= '0' && t <= '9') {
        x = x * 10 + t - '0';
        t = getchar();
    }
    x *= f;
}

template<class T>inline void chkmin(T &x, T y) { if (x > y) x = y; }
template<class T>inline void chkmax(T &x, T y) { if (x < y) x = y; }

const int maxn = 100005;
const double pi = acos(-1.0);

int n;
int r;
int v;
int s;
int f;
double prs;

void input()
{
    Read(n);
    Read(r);
    Read(v);
}

bool check(double t)
{
    double ang = pi * (fmod(t, prs) / prs);
    return v * t + 2 * sin(ang) * r >= f - s;
}

void solve()
{
    while (n --) {
        Read(s);
        Read(f);
        double l = 0;
        double r = 1e10;
        double mid;
        prs = (2 * pi * ::r) / v;
        int trial = 100;
        while (trial --) {
            mid = (l + r) / 2;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        printf("%.10f\n", (l + r) / 2);
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    input();
    solve();

#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

template<class T>inline void Read(T &x)
{
    int f = 1;
    char t = getchar();
    while (t < '0' || t > '9') {
        if (t == '-') f = -1;
        t = getchar();
    }
    x = 0;
    while (t >= '0' && t <= '9') {
        x = x * 10 + t - '0';
        t = getchar();
    }
    x *= f;
}

template<class T>inline void chkmin(T &x, T y) { if (x > y) x = y; }
template<class T>inline void chkmax(T &x, T y) { if (x < y) x = y; }

const int maxn = 100005;
const double pi = acos(-1.0);

int n;
int r;
int v;
int s;
int f;
double prs;

void input()
{
    Read(n);
    Read(r);
    Read(v);
}

bool check(double t)
{
    double ang = pi * (fmod(t, prs) / prs);
    return v * t + 2 * sin(ang) * r >= f - s;
}

void solve()
{
    while (n --) {
        Read(s);
        Read(f);
        double l = 0;
        double r = (f - s) / v;
        double mid;
        prs = (2 * pi * ::r) / v;
        int trial = 200;
        while (trial --) {
            mid = (l + r) / 2;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        printf("%.10f\n", (l + r) / 2);
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    input();
    solve();

#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

template<class T>inline void Read(T &x)
{
    int f = 1;
    char t = getchar();
    while (t < '0' || t > '9') {
        if (t == '-') f = -1;
        t = getchar();
    }
    x = 0;
    while (t >= '0' && t <= '9') {
        x = x * 10 + t - '0';
        t = getchar();
    }
    x *= f;
}

template<class T>inline void chkmin(T &x, T y) { if (x > y) x = y; }
template<class T>inline void chkmax(T &x, T y) { if (x < y) x = y; }

const int maxn = 100005;
const double pi = acos(-1.0);

int n;
int r;
int v;
int s;
int f;
double prs;

void input()
{
    Read(n);
    Read(r);
    Read(v);
}

bool check(double t)
{
    double ang = pi * (fmod(t, prs) / prs);
    return v * t + 2 * sin(ang) * r >= f - s;
}

void solve()
{
    while (n --) {
        Read(s);
        Read(f);
        double l = 0;
        double r = 1e10;
        double mid;
        prs = (2 * pi * ::r) / v;
        int trial = 200;
        while (trial --) {
            mid = (l + r) / 2;
            if (check(mid)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        printf("%.10f\n", (l + r) / 2);
    }
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    input();
    solve();

#ifndef ONLINE_JUDGE
    fclose(stdin);
    fclose(stdout);
#endif
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define INF 1e+9
#define mp make_pair
#define pb push_back
#define fi first
#define fs first
#define se second
#define i64 long long
#define li long long
#define lint long long
#define pii pair<int, int>
#define vi vector<int>

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

const int it_const = 100;

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    //freopen("outp", "w", stdout);
#else
    // freopen(TASKNAME ".in", "r", stdin);
    // freopen(TASKNAME ".out", "w", stdout);
#endif
    int n, R, v;
    scanf("%d%d%d", &n, &R, &v);
    forn(j, n)
    {
        int s, f;
        scanf("%d%d", &s, &f);
        double len = f - s;
        double r = len / v;
        double l = (len - 2 * R) / v;
        double angle = v / 2 / R;
        forn(it, it_const)
        {
            double m = (l + r) / 2;
            if (v * m + 2 * R * abs(sin(angle * m)) >= len)
                r = m;
            else l = m;
        }
        printf("%.10lf\n", l);
    }
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <iostream>
#include <cassert>
#include <cmath>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>

using namespace std;

#define INF 1e+9
#define mp make_pair
#define pb push_back
#define fi first
#define fs first
#define se second
#define i64 long long
#define li long long
#define lint long long
#define pii pair<int, int>
#define vi vector<int>

#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++)

const int it_const = 100;

int main() {
#ifdef LOCAL
    freopen("inp", "r", stdin);
    //freopen("outp", "w", stdout);
#else
    // freopen(TASKNAME ".in", "r", stdin);
    // freopen(TASKNAME ".out", "w", stdout);
#endif
    int n, R, v;
    scanf("%d%d%d", &n, &R, &v);
    forn(j, n)
    {
        int s, f;
        scanf("%d%d", &s, &f);
        double len = f - s;
        double l = (len - 2 * R) / v;
        double r = len / v;
        double angle = (double)v / 2 / R;
        forn(it, it_const)
        {
            double m = (l + r) / 2;
            if (v * m + 2 * R * abs(sin(angle * m)) >= len)
                r = m;
            else l = m;
        }
        printf("%.10lf\n", l);
    }
}


#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-7;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n, r, v;
double ans, HF;
bool check(double t)
{
	double x = t * v;
	if(x + sin(x / r) * r >= HF + eps) return 1;
	if(x - sin(x / r) * r >= HF + eps) return 1;
	return 0;
}

int main()
{
	n = read();
	r = read();
	v = read();
	for(int i = 0; i < n; i ++)
	{
		int s, f;
		s = read();
		f = read();
		int L = f - s;
        HF = L / 2.0;
        double l = 0.0, r = HF / v;
        while ((r - l) >= eps)
        {
            double mid = (l + r) / 2.0;
            if (check(mid)) r = mid;
            else l = mid;
        }
        printf("%.12f\n",2 * l);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
	return x * f;
}
int n, r, v;
double ans, HF;
bool check(double t)
{
	double x = t * v;
	if(x + sin(x / r) * r >= HF + eps) return 1;
	if(x - sin(x / r) * r >= HF + eps) return 1;
	return 0;
}

int main()
{
	n = read();
	r = read();
	v = read();
	for(int i = 0; i < n; i ++)
	{
		int s, f;
		s = read();
		f = read();
		int L = f - s;
        HF = L / 2.0;
        double l = 0, r = HF / v;
        while ((r - l) >= eps)
        {
            double mid = (l + r) / 2.0;
            if (check(mid)) r = mid;
            else l = mid;
        }
        printf("%.12f\n",2 * l);
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
const double eps = 1e-12;
int n;
ll r, v;
double ans, HF;
bool check(double t)
{
	double x = t * v;
	if(x + sin(x / r) * r >= HF + eps) return 1;
	if(x - sin(x / r) * r >= HF + eps) return 1;
	return 0;
}

int main()
{
	scanf("%d %I64d %I64d",&n ,&r, &v);
	for(int i = 0; i < n; i ++)
	{
		ll s, f;
		scanf("%I64d%I64d", &s, &f);
		long long L = f - s;
        HF = L / 2.0;
        double l = 0, r = HF / v;
        while ((r - l) >= eps)
        {
            double mid = (l + r) / 2.0;
            if (check(mid)) r = mid;
            else l = mid;
        }
        printf("%.12f\n",2 * l);
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-12;
int n, r, v;
double ans, HF;
bool check(double t)
{
	double x = t * v;
	if(x + sin(x / r) * r >= HF + eps) return 1;
	if(x - sin(x / r) * r >= HF + eps) return 1;
	return 0;
}

int main()
{
	scanf("%d%d%d",&n ,&r, &v);
	for(int i = 0; i < n; i ++)
	{
		int s, f;
		scanf("%d%d", &s, &f);
		int L = f - s;
        HF = L / 2.0;
        double l = 0, r = HF / v;
        while ((r - l) >= eps)
        {
            double mid = (l + r) / 2.0;
            if (check(mid)) r = mid;
            else l = mid;
        }
        printf("%.12f\n",2 * l);
	}

	return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define DEBUG(x) cerr << '>' << #x << ':' << (x) << endl;
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,a) for(int i=0; i<(a);++i)
inline bool EQ(double a, double b) {return fabs(a-b) < 1e-9;}

static const double PI = 2 * acos(0);
typedef long long ll;

bool can(double dist, double angle) {
  angle /= 2;
  double maxDist = 2 * (angle + sin(angle));
  return dist <= maxDist;
}

double getAngle(double dist) {
  double l = 0;
  double h = 2*PI;
  REP(i,100) {
    double m = (l + h) / 2;
    if (can(dist, m)) {
      h = m;
    } else {
      l = m;
    }
  }
  return (l + h) / 2;
}

int main() {
  DEBUG(PI)
  int N;
  double R, V, S, F;
  scanf("%d%lf%lf", &N, &R, &V);
  double circ = 2*PI*R;
  REP(i,N) {
    scanf("%lf%lf", &S, &F);
    double D = F-S;
    ll whole = (ll)(D / circ);
    double t = whole * circ / V;
    D -= whole * circ;
    t += getAngle(D / R) * R / V;
    printf("%.12lf\n", t);
  }
  return 0;
}


#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;
#define DEBUG(x) cerr << '>' << #x << ':' << (x) << endl;
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define FORD(i,a,b) for(int i=(a);i>=(b);--i)
#define REP(i,a) for(int i=0; i<(a);++i)
inline bool EQ(double a, double b) {return fabs(a-b) < 1e-9;}

typedef long long ll;

bool can(double dist, double angle) {
  angle /= 2;
  double maxDist = 2 * (angle + sin(angle));
  return dist <= maxDist;
}

double getAngle(double dist) {
  double l = 0;
  double h = 2*M_PI;
  REP(i,100) {
    double m = (l + h) / 2;
    if (can(dist, m)) {
      h = m;
    } else {
      l = m;
    }
  }
  return (l + h) / 2;
}

int main() {
  int N;
  double R, V, S, F;
  scanf("%d%lf%lf", &N, &R, &V);
  double circ = 2*M_PI*R;
  REP(i,N) {
    scanf("%lf%lf", &S, &F);
    double D = F-S;
    ll whole = (ll)(D / circ);
    double t = whole * circ / V;
    D -= whole * circ;
    t += getAngle(D / R) * R / V;
    printf("%.12lf\n", t);
  }
  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  scanf("%d%lf%lf", &N, &R, &V);
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = 0, rb = 1E10;
    for(int j=0; j<50; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
      if((rb - lb)/V < 1E-7) break;
    }

    printf("%.10f\n", lb+rb);
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  scanf("%d%lf%lf", &N, &R, &V);
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = (x-R)/V, rb = (x+R)/V;
    for(int j=0; j<60; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
      if(rb - lb < 1E-7) break;
    }

    printf("%.10f\n", lb+rb);
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  scanf("%d%lf%lf", &N, &R, &V);
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = 0, rb = 1E20;
    for(int j=0; j<100; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
      if(rb - lb < 1E-7) break;
    }

    printf("%.10f\n", lb+rb);
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  scanf("%d%lf%lf", &N, &R, &V);
  W = V / R;

  for(int i=0; i<N; i++)
  {
    scanf("%lf%lf", &s, &f);
    ld x = (f - s) / 2;
    ld lb = (x-R)/V, rb = (x+R)/V;
    for(int j=0; j<60; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
      if(rb - lb < 1E-7) break;
    }

    printf("%.10f\n", lb+rb);
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  IOS;
  cin>>N>>R>>V;
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = 0, rb = 1E20;
    for(int j=0; j<100; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
    }

    cout<<fixed<<setprecision(10)<<lb+rb<<"\n";
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  scanf("%d%lf%lf", &N, &R, &V);
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = 0, rb = 1E10;
    for(int j=0; j<60; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
      if((rb - lb)/V < 1E-7) break;
    }

    printf("%.10f\n", lb+rb);
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef long double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  IOS;
  cin>>N>>R>>V;
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = 0, rb = 1E20;
    for(int j=0; j<80; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
    }

    cout<<fixed<<setprecision(10)<<lb+rb<<"\n";
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  IOS;
  cin>>N>>R>>V;
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = 0, rb = 1E20;
    for(int j=0; j<80; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
    }

    cout<<fixed<<setprecision(10)<<lb+rb<<"\n";
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  IOS;
  cin>>N>>R>>V;
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = 0, rb = 1E20;
    for(int j=0; j<100; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
      if(rb - lb < 1E-7) break;
    }

    cout<<fixed<<setprecision(10)<<lb+rb<<"\n";
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef long double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  IOS;
  cin>>N>>R>>V;
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = 0, rb = 1E20;
    for(int j=0; j<150; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
    }

    cout<<fixed<<setprecision(10)<<lb+rb<<"\n";
  }

  return 0;
}


#include<bits/stdc++.h>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define FZ(n) memset((n),0,sizeof(n))
#define FMO(n) memset((n),-1,sizeof(n))
#define MC(n,m) memcpy((n),(m),sizeof(n))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define FOR(x,y) for(__typeof(y.begin())x=y.begin();x!=y.end();x++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
// Let's Fight!

typedef double ld;

int N;
ld R, V, W;
ld s, f;

int main()
{
  scanf("%d%lf%lf", &N, &R, &V);
  W = V / R;

  for(int i=0; i<N; i++)
  {
    cin>>s>>f;
    ld x = (f - s) / 2;
    ld lb = 0, rb = 1E10;
    for(int j=0; j<60; j++)
    {
      ld mb = (lb + rb) / 2;
      ld val = V*mb + R*fabs(sin(W*mb));
      if(val < x)
        lb = mb;
      else
        rb = mb;
      //if((rb - lb)/V < 1E-7) break;
    }

    printf("%.10f\n", lb+rb);
  }

  return 0;
}


#include <cstdio>
#include <cmath>
using namespace std;

const double PI = acos(-1.0);
double r, v, s, f, len;
int n;

double check(double t) {
    double s = v * t;
    double a = fmod(t*v/r, 2*PI) / 2;
    return s + 2*r*sin(a) >= len;
}

int main() {
    scanf("%d%lf%lf", &n, &r, &v);
    while(n--) {
        scanf("%lf%lf", &s, &f);
        len = f - s;
        double l = 0, r = len / v;
        int k = 50;
        while(k--) {
            double t = (l+r) / 2;
            if(check(t)) r = t;
            else
                l = t;
        }
        printf("%.12lf\n", l);
    }
    return 0;
}


#include <fstream>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <iomanip>

#define maxn 200010

using namespace std;

int n;
double r,v,s,f;

double mod (double a, double b)
{
    return a - ((int)(a/b))*b;
}

void rot (double &px, double &py, double cx, double cy, double angle)
{
    double tx = px, ty = py;
    px = tx*cos(angle) - ty*sin(angle);
    py = tx*sin(angle) + ty*cos(angle);
}

bool check (double time)
{
    double dist = time*v;
    double centerx = 0;
    double centery = 0;
    double sensorx1 = 0;
    double sensory1 = r;
    double sensorx2 = 0;
    double sensory2 = r;
    double angle = dist/r;
    rot(sensorx1, sensory1, centerx, centery, angle/2);
    rot(sensorx2, sensory2, centerx, centery, -angle/2);
    return (s + dist + fabs(sensorx2 - sensorx1) >= f);
}

int main()
{
    //freopen("egipt.in", "r", stdin);
    cin >> n >> r >> v;

    for (int i = 1; i <= n; ++i)
    {
        cin >> s >> f;

        int time = 120;
        double lo = 0, hi = 1e10;
        while(time)
        {
            double mid = (lo + hi)/2;
            if (check(mid))
                hi = mid;
            else lo = mid;
            --time;
        }
        cout << fixed << setprecision(11) << hi << "\n";
    }
}


#include <fstream>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <iomanip>

#define maxn 200010

using namespace std;

int n,s,f;
double r,v;

double mod (double a, double b)
{
    return a - ((int)(a/b))*b;
}

void rot (double &px, double &py, double cx, double cy, double angle)
{
    double tx = px, ty = py;
    px = tx*cos(angle) - ty*sin(angle);
    py = tx*sin(angle) + ty*cos(angle);
}

bool check (double time)
{
    double dist = time*v;
    double centerx = 0;
    double centery = 0;
    double sensorx1 = 0;
    double sensory1 = r;
    double sensorx2 = 0;
    double sensory2 = r;
    double angle = dist/r;
    rot(sensorx1, sensory1, centerx, centery, angle/2);
    rot(sensorx2, sensory2, centerx, centery, -angle/2);
    return (s + dist + fabs(sensorx2 - sensorx1) >= f);
}

int main()
{
    //freopen("egipt.in", "r", stdin);
    scanf("%d %lf %lf", &n, &r, &v);

    for (int i = 1; i <= n; ++i)
    {
        scanf("%d %d", &s, &f);

        int time = 90;
        double lo = 0, hi = 1e10;
        while(time)
        {
            double mid = (lo + hi)/2;
            if (check(mid))
                hi = mid;
            else lo = mid;
            --time;
        }
        printf("%.11lf\n", hi);
    }
}


#include <fstream>
#include <algorithm>
#include <iostream>
#include <cassert>
#include <iomanip>

#define maxn 200010

using namespace std;

int n,s,f;
double r,v;

double mod (double a, double b)
{
    return a - ((int)(a/b))*b;
}

void rot (double &px, double &py, double cx, double cy, double angle)
{
    double tx = px, ty = py;
    px = tx*cos(angle) - ty*sin(angle);
    py = tx*sin(angle) + ty*cos(angle);
}

bool check (double time)
{
    double dist = time*v;
    double centerx = 0;
    double centery = 0;
    double sensorx1 = 0;
    double sensory1 = r;
    double sensorx2 = 0;
    double sensory2 = r;
    double angle = dist/r;
    rot(sensorx1, sensory1, centerx, centery, angle/2);
    rot(sensorx2, sensory2, centerx, centery, -angle/2);
    return (s + dist + fabs(sensorx2 - sensorx1) >= f);
}

int main()
{
    //freopen("egipt.in", "r", stdin);
    scanf("%d %lf %lf", &n, &r, &v);

    for (int i = 1; i <= n; ++i)
    {
        scanf("%d %d", &s, &f);

        int time = 60;
        double lo = 0, hi = 1e10;
        while(time)
        {
            double mid = (lo + hi)/2;
            if (check(mid))
                hi = mid;
            else lo = mid;
            --time;
        }
        printf("%.11lf\n", hi);
    }
}


#include <bits/stdc++.h>
using namespace std;

char s[1111111];
int c[10];
vector <int> o;

int main() {
	cin >> s;
	c[1]=c[6]=c[8]=c[9]=1;
	int r = 0;
	for (int i=0; s[i]; ++i) {
		int d = s[i] - '0';
		if (c[d]) --c[d];
		else if (!d) ++c[d];
		else o.push_back(d), r = (r * 10 + d) % 7;
	}
	r = r * 10000 % 7;
	char buf[]="1689";
	do {
		int x;
		sscanf(buf, "%d", &x);
		if ((x + r) % 7 == 0) {
			for (auto i: o) cout << i;
			cout << buf;
			for (int i=0; i<c[0]; ++i) cout << 0;
			break;
		}
	} while (next_permutation(buf, buf+4));
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

char s[1111111];
int c[10];
vector <int> o;

int main() {
	cin >> s;
	c[1]=c[6]=c[8]=c[9]=1;
	int r = 0;
	for (int i=0; s[i]; ++i) {
		int d = s[i] - '0';
		if (c[d]) --c[d];
		else o.push_back(d), r = (r * 10 + d) % 7;
	}
	char buf[]="1689";
	do {
		int x;
		sscanf(buf, "%d", &x);
		x = x * 2 % 7;
		if (x == r) {
			int i;
			for (i=0; i<(int)o.size()&&o[i]==0; ++i);
			for (int j=i; j<(int)o.size(); ++j) cout << o[j];
			cout << buf;
			for (int j=0; j<i; ++j) cout << 0;
			break;
		}
	} while (next_permutation(buf, buf+4));
	return 0;
}


#include <bits/stdc++.h>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

const int INF = int(1e9 + 7);
typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;

int toInt(string s)
{
	int res = 0;
	for (int i = 0; i < s.size(); i++)
	{
		res = (res * 10) + s[i]-'0';
	}
	return res;
}

int potMod[6];

int getMod(string s, int offset)
{
	int idx = offset%6;
	int res = 0;
	for (int i = s.size()-1; i >= 0; i--)
	{
		res += (potMod[idx] * (s[i]-'0')%7)%7;
		res %= 7;
		idx = (idx + 1) % 6;
	}
	return res;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    // 10000 % 7 => 4
    //string suf[7] = {"1869", "6819", "1689", "6198", "8691", "8916", "8196"};
    string suf[7] = {"1869", "8196", "8916", "8691", "6198", "1689", "6819"};

    for (int i = 0, j = 1; i < 6; j *= 10, i++)
    {
    	potMod[i] = j%7;
    	//cout << potMod[i] << ' ';
    }
    string s;
    cin >> s;
    for (int j = 0; j < 4; j++)
    {
    	for (int i = 0; i < s.size(); i++)
    	{
    		if (s[i] == suf[0][j])
    		{
    			s = s.substr(0, i) + s.substr(i+1);
    			break;
    		}
    	}
    }
    string ceros = "";
    //cout << s;
    for (int i = 0; i < s.size(); i++)
    {
    	if (s[i] == '0')
    	{
    		ceros += '0';
    		s = s.substr(0, i) + s.substr(i+1);
    		i--;
    	}
    }
    int mod = getMod(s, 4+ceros.size());
    int need = 7 - mod, idx = need;
    /*
    cout << "sdfasdf" << endl;
    cout << need << endl;
    for (int i = 0; i < 7; i++)
    {
    	if ( (i * potMod[ ceros.size()%6 ])%7 == need )
    	{
    		idx = i;
    		break;
    	}
    }
    cout << "hgaskdhuf" << endl;
    */
    cout << s << suf[mod] << ceros << '\n';
    return 0;
}
// PLUS ULTRA!


#include <bits/stdc++.h>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

const int INF = int(1e9 + 7);
typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;

int toInt(string s)
{
	int res = 0;
	for (int i = 0; i < s.size(); i++)
	{
		res = (res * 10) + s[i]-'0';
	}
	return res;
}

int potMod[6];

int getMod(string s, int offset)
{
	int idx = offset%6;
	int res = 0;
	for (int i = s.size()-1; i >= 0; i--)
	{
		res += potMod[idx] * (s[i]-'0')%7;
		res %= 7;
		idx = (idx + 1) % 6;
	}
	return res;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);

    // 10000 % 7 = 4
    string suf[7] = {"1869", "6819", "1689", "6198", "8691", "8916", "8196"};

    for (int i = 0, j = 1; i < 6; j *= 10, i++)
    {
    	potMod[i] = j%7;
    	//cout << potMod[i] << ' ';
    }
    string s;
    cin >> s;
    for (int j = 0; j < 4; j++)
    {
    	for (int i = 0; i < s.size(); i++)
    	{
    		if (s[i] == suf[0][j])
    		{
    			s = s.substr(0, i) + s.substr(i+1);
    			break;
    		}
    	}
    }
    string ceros = "";
    //cout << s;
    for (int i = 0; i < s.size(); i++)
    {
    	if (s[i] == '0')
    	{
    		ceros += '0';
    		s = s.substr(0, i) + s.substr(i+1);
    		i--;
    	}
    }
    int mod = getMod(s, 4+ceros.size());
    int idx = mod * potMod[ ceros.size()%6 ];
    idx %= 7;
    cout << s << suf[idx] << ceros << '\n';
    return 0;
}
// PLUS ULTRA!


#include <bits/stdc++.h>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

const int INF = int(1e9 + 7);
typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;

int toInt(string s)
{
	int res = 0;
	for (int i = 0; i < s.size(); i++)
	{
		res = (res * 10) + s[i]-'0';
	}
	return res;
}

int potMod[6];

int getMod(string s, int offset)
{
	int idx = offset%6;
	int res = 0;
	for (int i = s.size()-1; i >= 0; i--)
	{
		res += (potMod[idx] * (s[i]-'0')%7)%7;
		res %= 7;
		idx = (idx + 1) % 6;
	}
	return res;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    // 10000 % 7 => 4
    //string suf[7] = {"1869", "6819", "1689", "6198", "8691", "8916", "8196"};
    string suf[7] = {"1869", "8196", "8916", "8691", "6198", "1689", "6819"};

    for (int i = 0, j = 1; i < 6; j *= 10, i++)
    {
    	potMod[i] = j%7;
    	//cout << potMod[i] << ' ';
    }
    string s;
    cin >> s;
    for (int j = 0; j < 4; j++)
    {
    	for (int i = 0; i < s.size(); i++)
    	{
    		if (s[i] == suf[0][j])
    		{
    			s = s.substr(0, i) + s.substr(i+1);
    			break;
    		}
    	}
    }
    string ceros = "";
    //cout << s;
    for (int i = 0; i < s.size(); i++)
    {
    	if (s[i] == '0')
    	{
    		ceros += '0';
    		s = s.substr(0, i) + s.substr(i+1);
    		i--;
    	}
    }
    int mod = getMod(s, 4);
    int need = 7 - mod, idx = need;
    /*
    cout << "sdfasdf" << endl;
    cout << need << endl;
    for (int i = 0; i < 7; i++)
    {
    	if ( (i * potMod[ ceros.size()%6 ])%7 == need )
    	{
    		idx = i;
    		break;
    	}
    }
    cout << "hgaskdhuf" << endl;
    */
    cout << s << suf[mod] << ceros << '\n';
    return 0;
}
// PLUS ULTRA!


#include <bits/stdc++.h>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

const int INF = int(1e9 + 7);
typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;

int toInt(string s)
{
	int res = 0;
	for (int i = 0; i < s.size(); i++)
	{
		res = (res * 10) + s[i]-'0';
	}
	return res;
}

int potMod[6];

int getMod(string s, int offset)
{
	int idx = offset%6;
	int res = 0;
	for (int i = s.size()-1; i >= 0; i--)
	{
		res += potMod[idx] * (s[i]-'0')%7;
		res %= 7;
		idx = (idx + 1) % 6;
	}
	return res;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    // 10000 % 7 => 4
  //string suf[7] = {"1869", "6819", "1689", "6198", "8691", "8916", "8196"};
    string suf[7] = {"1869", "8196", "8916", "8691", "6198", "1689", "6819"};

    for (int i = 0, j = 1; i < 6; j *= 10, i++)
    {
    	potMod[i] = j%7;
    	//cout << potMod[i] << ' ';
    }
    string s;
    cin >> s;
    for (int j = 0; j < 4; j++)
    {
    	for (int i = 0; i < s.size(); i++)
    	{
    		if (s[i] == suf[0][j])
    		{
    			s = s.substr(0, i) + s.substr(i+1);
    			break;
    		}
    	}
    }
    string ceros = "";
    //cout << s;
    for (int i = 0; i < s.size(); i++)
    {
    	if (s[i] == '0')
    	{
    		ceros += '0';
    		s = s.substr(0, i) + s.substr(i+1);
    		i--;
    	}
    }
    int mod = getMod(s, 4+ceros.size());
    int idx = mod * potMod[ ceros.size()%6 ];
    idx %= 7;
    cout << s << suf[idx] << ceros << '\n';
    return 0;
}
// PLUS ULTRA!


#include <bits/stdc++.h>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;

const int INF = int(1e9 + 7);
typedef long long       ll;
typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;

int toInt(string s)
{
	int res = 0;
	for (int i = 0; i < s.size(); i++)
	{
		res = (res * 10) + s[i]-'0';
	}
	return res;
}

int potMod[6];

int getMod(string s, int offset)
{
	int idx = offset%6;
	int res = 0;
	for (int i = s.size()-1; i >= 0; i--)
	{
		res += (potMod[idx] * (s[i]-'0')%7)%7;
		res %= 7;
		idx = (idx + 1) % 6;
	}
	return res;
}

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    // 10000 % 7 => 4
    //string suf[7] = {"1869", "6819", "1689", "6198", "8691", "8916", "8196"};
    string suf[7] = {"1869", "8196", "8916", "8691", "6198", "1689", "6819"};

    for (int i = 0, j = 1; i < 6; j *= 10, i++)
    {
    	potMod[i] = j%7;
    	//cout << potMod[i] << ' ';
    }
    string s;
    cin >> s;
    for (int j = 0; j < 4; j++)
    {
    	for (int i = 0; i < s.size(); i++)
    	{
    		if (s[i] == suf[0][j])
    		{
    			s = s.substr(0, i) + s.substr(i+1);
    			break;
    		}
    	}
    }
    string ceros = "";
    string newS = "";
    //cout << s;
    for (int i = 0; i < s.size(); i++)
    {
    	if (s[i] == '0')
    	{
    		ceros += '0';
    	}
    	else newS += s[i];
    }
    s = newS;
    int mod = getMod(s, 4);
    int need = 7 - mod, idx = need;
    /*
    cout << "sdfasdf" << endl;
    cout << need << endl;
    for (int i = 0; i < 7; i++)
    {
    	if ( (i * potMod[ ceros.size()%6 ])%7 == need )
    	{
    		idx = i;
    		break;
    	}
    }
    cout << "hgaskdhuf" << endl;
    */
    cout << s << suf[mod] << ceros << '\n';
    return 0;
}
// PLUS ULTRA!


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include<queue>
#include <map>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double de;
const int ar = 100000;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//1869 = 0
	//1968 = 1
	//6981 = 2
	//6891 = 3
	//8961 = 4
	//1986 = 5
	//1896 = 6
	string s, t;
	cin >> s;
	bool one = 0, eig = 0, six = 0, nine = 0;
	for (int w = 0; w < s.size(); w++) {
		if (s[w] == '1' && one == 0) {
			one = 1;
			continue;
		}
		if (s[w] == '6' && six == 0) {
			six = 1;
			continue;
		}
		if (s[w] == '8' && eig == 0) {
			eig = 1;
			continue;
		}
		if (s[w] == '9' && nine == 0) {
			nine = 1;
			continue;
		}
		 t += s[w];

	}
	int zero = 0;
	for (int w = 0; w < t.size(); w++) {
		if (t[w] == '0') zero++;
	}
	if (zero == t.size()) {
		cout << "1869" << t;
		return 0;
	}
	t += "0000";
	sort(t.rbegin(),t.rend());
	ll n = 7;
	ll c = t[0] - '0';
	c %= n;
	for (int w = 0; w < t.size() - 1; w++) {
		c %= n;
		c *= 10;
		c += (t[w + 1] - '0');
		c %= n;
	}
	for (int w = 0; w < t.size() - 4; w++) cout << t[w];
	if (c == 0) {
		cout << "1869";
	}
	if (c == 1) cout << "1896";
	if (c == 2) cout << "1986";
	if (c == 3) cout << "1698";
	if (c == 4) cout << "6891";
	if (c == 5) cout << "6981";
	if (c == 6) cout << "1968";
	cout << endl;

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include<queue>
#include <map>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double de;
const int ar = 100000;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//1869 = 0
	//1968 = 1
	//6981 = 2
	//6891 = 3
	//8961 = 4
	//1986 = 5
	//1896 = 6
	string s,t;
	cin >> s;
	bool one = 0, eig = 0, six = 0, nine = 0;
	for (int w = 0; w < s.size(); w++) {
		if (s[w] == '1' && one == 0) {
			one = 1;
			continue;
		}
		if (s[w] == '6' && six == 0) {
			six = 1;
			continue;
		}
		if (s[w] == '8' && eig == 0) {
			eig = 1;
			continue;
		}
		if (s[w] == '9' && nine == 0) {
			nine = 1;
			continue;
		}
		t += s[w];

	}
	int zero = 0;
	for (int w = 0; w < t.size(); w++) {
		if (t[w] == '0') zero++;
	}
	if (zero == t.size()) {
		cout << "1869" << t;
		return 0;
	}
	t += "0000";
	ll n = 7;
	ll c = t[0] - '0';
	c %= n;
	for (int w = 0; w < t.size() - 1; w++) {
		c %= n;
		c *= 10;
		c += (t[w + 1] - '0');
		c %= n;
	}
		for (int w = 0; w < t.size() - 4; w++) cout << t[w];
	if (c == 0) {
		cout << "1869" ;
	}
	if (c == 1) cout << "1896" ;
	if (c == 2) cout << "1986" ;
	if (c == 3) cout << "8961" ;
	if (c == 4) cout << "6891" ;
	if (c == 5) cout << "6981" ;
	if (c == 6) cout << "1968" ;
		cout << endl;

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include<queue>
#include <map>
#include<stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double de;
const int ar = 100000;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	//1869 = 0
	//1968 = 1
	//6981 = 2
	//6891 = 3
	//8961 = 4
	//1986 = 5
	//1896 = 6
	string s, t;
	cin >> s;
	bool one = 0, eig = 0, six = 0, nine = 0;
	for (int w = 0; w < s.size(); w++) {
		if (s[w] == '1' && one == 0) {
			one = 1;
			continue;
		}
		if (s[w] == '6' && six == 0) {
			six = 1;
			continue;
		}
		if (s[w] == '8' && eig == 0) {
			eig = 1;
			continue;
		}
		if (s[w] == '9' && nine == 0) {
			nine = 1;
			continue;
		}
		 t += s[w];

	}
	int zero = 0;
	for (int w = 0; w < t.size(); w++) {
		if (t[w] == '0') zero++;
	}
	if (zero == t.size()) {
		cout << "1869" << t;
		return 0;
	}
	t += "0000";
	sort(t.rebgin(),t.rend());
	ll n = 7;
	ll c = t[0] - '0';
	c %= n;
	for (int w = 0; w < t.size() - 1; w++) {
		c %= n;
		c *= 10;
		c += (t[w + 1] - '0');
		c %= n;
	}
	for (int w = 0; w < t.size() - 4; w++) cout << t[w];
	if (c == 0) {
		cout << "1869";
	}
	if (c == 1) cout << "1896";
	if (c == 2) cout << "1986";
	if (c == 3) cout << "1698";
	if (c == 4) cout << "6891";
	if (c == 5) cout << "6981";
	if (c == 6) cout << "1968";
	cout << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
   string s ;
   cin >> s ;
   int l=0;
   for(int i=0 ; i<s.size() ; i++)
   {
       l=(l*10+s[i]-'0')%7 ;
   }
   if(l==0)
   {
       cout << s ;
       return 0 ;
   }

   do {
        int l=0 ;
    for (int i=0 ; i<s.size() ; i++)
   {
       l=(l*10+s[i]-'0')%7 ;
   }
   if(l==0)
   {
       cout << s ;return 0;
   }
   }while(next_permutation(s.begin() , s.end()) ) ;
   cout<< "0" ;
  return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;

int main() {
   string s ;
   cin >> s ;
   LL l=0;
   for(int i=0 ; i<s.size() ; i++)
   {
       l=(l*10+s[i]-'0')%7 ;
   }
   if(l==0)
   {
       cout << s ;
       return 0 ;
   }
    sort(s.begin() , s.end());
   do {
       // cout << s << endl ;
        LL l=0 ;
    for (int i=0 ; i<s.size() ; i++)
   {
       l=(l*10+s[i]-'0')%7 ;
   }
   if(l==0)
   {
       cout << s ;return 0;
   }
   }while(next_permutation(s.begin() , s.end())) ;
   cout<< "0" ;
  return 0;
}


#include <bits/stdc++.h>

using namespace std;

int main() {
   string s ;
   cin >> s ;
   do {
        int x ;
        stringstream ss ;
        ss<<s ;
        ss>>x ;
        if(x%7==0 && s[0]!='0'){
            cout << x <<endl ;
            return 0 ;
        }

   }while(next_permutation(s.begin() , s.end()) ) ;
  return 0;
}


#include <bits/stdc++.h>
#define LL long long
using namespace std;

int main() {
   string s ;
   cin >> s ;
   LL l=0;
   for(int i=0 ; i<s.size() ; i++)
   {
       l=(l*10+s[i]-'0')%7 ;
   }
   if(l==0&&s[0]!='0')
   {
       cout << s ;
       return 0 ;
   }
    sort(s.begin() , s.end());
   do {
       // cout << s << endl ;
        LL l=0 ;
    for (int i=0 ; i<s.size() ; i++)
   {
       l=(l*10+s[i]-'0')%7 ;
   }
   if(l==0 && s[0]!='0')
   {
       cout << s ;return 0;
   }
   }while(next_permutation(s.begin() , s.end())) ;
   cout<< "0" ;
  return 0;
}


#include    <bits/stdc++.h>

#define     M_PI            3.14159265358979323846
#define     mod             1000000007
#define     inf             1000000000000000000
#define     mp              make_pair
#define     pb              push_back
#define     F               first
#define     S               second
#define     ll              long long
#define     pii             pair<int,int>
#define     pli             pair<ll,int>
#define     pil             pair<int,ll>
#define     pll             pair<ll,ll>
#define     si(t)           scanf("%d",&t)
#define     sii(m,n)        scanf("%d %d",&m,&n);
#define     sl(t)           scanf("%lld",&t)
#define     rep(i,n)        for(int i=0;i<n;i++)
#define     REP(i,a,b)      for(int i=a;i<=b;i++)
#define     RREP(i,a,b)     for(int i=a;i>=b;i--)
#define     N               1002

using namespace std;

string s,ans;
int arr[12],aa[12],num[5];

void fun(int a,int vis[],int k){
    if(a == 4){
        if(aa[k%7] == 0) aa[k%7] = k;
        return ;
    }
    rep(i,4){
        if(!vis[i]){
            int temp[4];
            rep(j,4) temp[j] = vis[j];
            temp[i] = 1;
            fun(a+1,temp,k*10+num[i]);
        }
    }
}

ll modpow(ll a,ll b,ll m){
    ll i;
    for(i=1; b ; b >>= 1){
        if(b & 1) i = (i*a)%m;
        i = (i*i)%m;
    }
    return i;
}

void ap(int a){
    string k = "";
    while(aa[a] != 0){
        k += (aa[a]%10+'0');
        aa[a] /= 10;
    }
    reverse(k.begin(),k.end());
    ans.append(k);
}

int main(){
    ans = "";
    cin>>s;
    int n = s.length();
    rep(i,n) arr[s[i]-'0']++;
    num[0] = 1; num[1] = 8; num[2] = 6; num[3] = 9;
    arr[1]--; arr[9]--;
    arr[8]--; arr[6]--;
    int vis[4]; memset(vis,0,sizeof vis);
    fun(0,vis,0);
    REP(i,1,9){
        rep(j,arr[i]) ans += i+'0';
    }
    ll p=0;
    int kk = ans.length();
    rep(i,kk){
        p = p+ (modpow(10,n-1-i,7)*(ans[i]-'0')%7)%7;
        p %= 7;
    }
    ap(p);
    rep(i,arr[0]) ans.append(1,'0');
    cout << ans << endl;
    return 0;
}


#include    <bits/stdc++.h>

#define     M_PI            3.14159265358979323846
#define     mod             1000000007
#define     inf             1000000000000000000
#define     mp              make_pair
#define     pb              push_back
#define     F               first
#define     S               second
#define     ll              long long
#define     pii             pair<int,int>
#define     pli             pair<ll,int>
#define     pil             pair<int,ll>
#define     pll             pair<ll,ll>
#define     si(t)           scanf("%d",&t)
#define     sii(m,n)        scanf("%d %d",&m,&n);
#define     sl(t)           scanf("%lld",&t)
#define     rep(i,n)        for(int i=0;i<n;i++)
#define     REP(i,a,b)      for(int i=a;i<=b;i++)
#define     RREP(i,a,b)     for(int i=a;i>=b;i--)
#define     N               1002

using namespace std;

string s,ans;
int arr[12],aa[12],num[5];

void fun(int a,int vis[],int k){
    if(a == 4){
        if(aa[k%7] == 0) aa[k%7] = k;
        return ;
    }
    rep(i,4){
        if(!vis[i]){
            int temp[4];
            rep(j,4) temp[j] = vis[j];
            temp[i] = 1;
            fun(a+1,temp,k*10+num[i]);
        }
    }
}

ll modpow(ll a,ll b,ll m){
    ll i;
    for(i=1; b ; b >>= 1){
        if(b & 1) i = (i*a)%m;
        a = (a*a)%m;
    }
    return i;
}

void ap(int a){
    //cout << a << endl;
    string k = "";
    while(aa[a] != 0){
        k += (aa[a]%10+'0');
        aa[a] /= 10;
    }
    reverse(k.begin(),k.end());
    ans.append(k);
}

int main(){
    ans = "";
    cin>>s;
    int n = s.length();
    rep(i,n) arr[s[i]-'0']++;
    num[0] = 1; num[1] = 8; num[2] = 6; num[3] = 9;
    arr[1]--; arr[9]--;
    arr[8]--; arr[6]--;
    if(arr[0] == n-4){
        printf("1869");
        rep(i,arr[0]) printf("0");
        printf("\n");
        return 0;
    }
    int vis[4]; memset(vis,0,sizeof vis);
    fun(0,vis,0);
    REP(i,1,9){
        rep(j,arr[i]) ans += i+'0';
    }
    rep(i,arr[0]) ans.append(1,'0');
    ll p=0;
    int kk = ans.length();
    rep(i,kk){
        p = p+ (modpow(10,n-1-i,7)*(ans[i]-'0')%7)%7;
        p %= 7;
        //cout << p << endl;
    }
    //p = p+ (modpow(10,arr[0],7);
    //cout << p << endl;
    ap((7-p+7)%7);

    cout << ans << endl;
    return 0;
}


#include    <bits/stdc++.h>

#define     M_PI            3.14159265358979323846
#define     mod             1000000007
#define     inf             1000000000000000000
#define     mp              make_pair
#define     pb              push_back
#define     F               first
#define     S               second
#define     ll              long long
#define     pii             pair<int,int>
#define     pli             pair<ll,int>
#define     pil             pair<int,ll>
#define     pll             pair<ll,ll>
#define     si(t)           scanf("%d",&t)
#define     sii(m,n)        scanf("%d %d",&m,&n);
#define     sl(t)           scanf("%lld",&t)
#define     rep(i,n)        for(int i=0;i<n;i++)
#define     REP(i,a,b)      for(int i=a;i<=b;i++)
#define     RREP(i,a,b)     for(int i=a;i>=b;i--)
#define     N               1002

using namespace std;

string s,ans;
int arr[12],aa[12],num[5];

void fun(int a,int vis[],int k){
    if(a == 4){
        if(aa[k%7] == 0) aa[k%7] = k;
        return ;
    }
    rep(i,4){
        if(!vis[i]){
            int temp[4];
            rep(j,4) temp[j] = vis[j];
            temp[i] = 1;
            fun(a+1,temp,k*10+num[i]);
        }
    }
}

ll modpow(ll a,ll b,ll m){
    ll i;
    for(i=1; b ; b >>= 1){
        if(b & 1) i = (i*a)%m;
        i = (i*i)%m;
    }
    return i;
}

void ap(int a){
    string k = "";
    while(aa[a] != 0){
        k += (aa[a]%10+'0');
        aa[a] /= 10;
    }
    reverse(k.begin(),k.end());
    ans.append(k);
}

int main(){
    ans = "";
    cin>>s;
    int n = s.length();
    rep(i,n) arr[s[i]-'0']++;
    num[0] = 1; num[1] = 8; num[2] = 6; num[3] = 9;
    arr[1]--; arr[9]--;
    arr[8]--; arr[6]--;
    if(arr[0] == n-4){
        printf("1869");
        rep(i,arr[0]) printf("0");
        printf("\n");
        return 0;
    }
    int vis[4]; memset(vis,0,sizeof vis);
    fun(0,vis,0);
    REP(i,1,9){
        rep(j,arr[i]) ans += i+'0';
    }
    rep(i,arr[0]) ans.append(1,'0');
    ll p=0;
    int kk = ans.length();
    rep(i,kk){
        p = p+ (modpow(10,n-1-i,7)*(ans[i]-'0')%7)%7;
        p %= 7;
    }
    //p = p+ (modpow(10,arr[0],7);
    //cout << p << endl;
    ap((7-p+7)%7);

    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
string a[10];
const int N = 100;
int cnt[N];
main()
{
    string s, r = "1689";
    cin >> s;
    for(int i = 0; i < s.size(); i ++)
     cnt[s[i] - 48] ++;
    cnt[1] --;
    cnt[6] --;
    cnt[8] --;
    cnt[9] --;
    do
    {
        int res = 0, i;
        for(i = 0; i < 4; i ++)
            res = res * 10 + r[i] - 48;
        a[res % 7] = r;
    }
    while(next_permutation(r.begin(), r.end()));
    int c = 0;
    for(int i = 9; i >= 1; i --)
    {
        for(int j = 1; j <= cnt[i]; j ++)
        {
            c = c * 10 + i;
            c %= 7;
            cout << i;
        }
    }
    if(c == 0)
        c = 7;
    cout << a[7 - c];
    for(int i = 1; i <= cnt[0]; i ++)
        cout << 0;
}


#include <bits/stdc++.h>
using namespace std;
string a[10];
const int N = 100;
int cnt[N];
main()
{
    string s, r = "1689";
    cin >> s;
    for(int i = 0; i < s.size(); i ++)
     cnt[s[i] - 48] ++;
    cnt[1] --;
    cnt[6] --;
    cnt[8] --;
    cnt[9] --;
    do
    {
        int res = 0, i;
        for(i = 0; i < 4; i ++)
            res = res * 10 + r[i] - 48;
        a[res % 7] = r;
    }
    while(next_permutation(r.begin(), r.end()));
    int c = 0;
    for(int i = 9; i >= 1; i --)
    {
        for(int j = 1; j <= cnt[i]; j ++)
        {
            c = c * 10 + i;
            c %= 7;
            cout << i;
        }
    }
    cout << a[7 - c];
    for(int i = 1; i <= cnt[0]; i ++)
        cout << 0;
}


#include <bits/stdc++.h>
using namespace std;
string a[10];
const int N = 100;
int cnt[N];
main()
{
    string s, r = "1689";
    cin >> s;
    for(int i = 0; i < s.size(); i ++)
     cnt[s[i] - 48] ++;
    cnt[1] --;
    cnt[6] --;
    cnt[8] --;
    cnt[9] --;
    do
    {
        int res = 0, i;
        for(i = 0; i < 4; i ++)
            res = res * 10 + r[i] - 48;
        a[res % 7] = r;
    }
    while(next_permutation(r.begin(), r.end()));
    int c = 0;
    for(int i = 9; i >= 1; i --)
    {
        for(int j = 1; j <= cnt[i]; j ++)
        {
            c = c * 10 + i;
            c %= 7;
            cout << i;
        }
    }
    cout << a[c];
    for(int i = 1; i <= cnt[0]; i ++)
        cout << 0;
}


#include <bits/stdc++.h>
using namespace std;
string a[10];
const int N = 100;
int cnt[N];
main()
{
    string s, r = "1689";
    cin >> s;
    for(int i = 0; i < s.size(); i ++)
     cnt[s[i] - 48] ++;
    cnt[1] --;
    cnt[6] --;
    cnt[8] --;
    cnt[9] --;
    do
    {
        int res = 0, i;
        for(i = 0; i < 4; i ++)
            res = res * 10 + r[i] - 48;
        a[res % 7] = r;
    }
    while(next_permutation(r.begin(), r.end()));
    int c = 0;
    for(int i = 9; i >= 1; i --)
    {
        for(int j = 1; j <= cnt[i]; j ++)
        {
            c = c * 10 + i;
            c %= 7;
            cout << i;
        }
    }
    c *= 10000;
    c %= 7;
    if(c == 0)
        c = 7;
    cout << a[7 - c];
    for(int i = 1; i <= cnt[0]; i ++)
        cout << 0;
}


#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
int fix[] = {1,6,8,9};
int cnt[10];
string tail[] = {
  "8169",
  "1968",
  "1689",
  "6198",
  "1698",
  "1986",
  "8196"
};

int main() {
  string a;
  cin >> a;
  memset(cnt, 0, sizeof(cnt));
  for (char i: a) cnt[i - '0']++;
  string res = "";
  for (int i: fix) if (cnt[i]) cnt[i]--;
  for (int i=1; i<=9; i++) {
    for (int j=0; j<cnt[i]; j++) res.push_back((char)(i + '0'));
  }
  int r = 0;
  for (char i: res) {
    int v = i - '0';
    r = (r * 10 + v) % 7;
  }
  r = r * 10000 % 7;
  r = (7 - r) % 7;
  res.insert(res.end(), tail[r].begin(), tail[r].end());
  for (int i=0; i<cnt[0]; i++) res.push_back('0');
  cout << res << endl;
  return 0;
}


#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
int fix[] = {1,6,8,9};
int cnt[10];
string tail[] = {
  "8169",
  "1968",
  "1689",
  "6198",
  "1698",
  "1986"
};

int main() {
  string a;
  cin >> a;
  memset(cnt, 0, sizeof(cnt));
  for (char i: a) cnt[i - '0']++;
  string res = "";
  for (int i: fix) if (cnt[i]) cnt[i]--;
  for (int i=1; i<=9; i++) {
    for (int j=0; j<cnt[i]; j++) res.push_back((char)(i + '0'));
  }
  int r = 0;
  for (char i: res) {
    int v = i - '0';
    r = (r * 10 + v) % 7;
  }
  r = r * 10000 % 7;
  res.insert(res.end(), tail[r].begin(), tail[r].end());
  for (int i=0; i<cnt[0]; i++) res.push_back('0');
  cout << res << endl;
  return 0;
}


#include <stdexcept>
#include <iostream>
#include <sstream>
#include <fstream>
#include <cassert>
#include <cstring>
#include <cstdarg>
#include <cstdio>
#include <random>
#include <cmath>
#include <ctime>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
#include <limits>
#include <bitset>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <array>
#include <list>
#include <map>
#include <set>
using namespace std;
#define ALL(a) (a).begin(), (a).end()
#define SZ(a) int((a).size())
#define MP(x, y) make_pair((x),(y))
#define FI first
#define SE second
#define LOWB(x) (x & (-x))
#define UNIQUE(a) sort(ALL(a)), (a).erase(unique(ALL(a)), (a).end())
#define HEIGHT(n) (sizeof(int) * 8 - __builtin_clz(n)) //height of range n segment tree
#define INF 1e9
#define INF_LL 4e18
#define rep(i,a,b) for(__typeof(b) i=a; i<(b); ++i)
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
int dx[] = {-1, 1, 0, 0};
int dy[] = {0, 0, -1, 1};
/*-----------------------------------*/
int fix[] = {1,6,8,9};
int cnt[10];
string tail[] = {
  "8169",
  "1968",
  "1689",
  "6198",
  "1698",
  "1986"
};

int main() {
  string a;
  cin >> a;
  memset(cnt, 0, sizeof(cnt));
  for (char i: a) cnt[i - '0']++;
  string res = "";
  for (int i: fix) if (cnt[i]) cnt[i]--;
  for (int i=1; i<=9; i++) {
    for (int j=0; j<cnt[i]; j++) res.push_back((char)(i + '0'));
  }
  int r = 0;
  for (char i: res) {
    int v = i - '0';
    r = (r * 10 + v) % 7;
  }
  r = r * 10000 % 7;
  r = (7 - r) % 7;
  res.insert(res.end(), tail[r].begin(), tail[r].end());
  for (int i=0; i<cnt[0]; i++) res.push_back('0');
  cout << res << endl;
  return 0;
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(!can_reach(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(j<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            System.out.println("YES");
        }
    }
    public static boolean can_reach(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                if(can_reach(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                if(can_reach(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                if(can_reach(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                if(can_reach(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(!can_reach(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            System.out.println("YES");
        }
    }
    public static boolean can_reach(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                if(can_reach(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                if(can_reach(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                if(can_reach(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                if(can_reach(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }
}