#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<queue>
#include<cmath>
#include<deque>
#include<stack>
#include<iomanip>
#include<string>
#include<random>
#include<cstdio>

using namespace std;

int cur, n;

inline bool cmp(int a, int b) {
	int d1 = a - cur, d2 = b - cur;
	if (d1 < 0) {
		d1 += n;
	}
	if (d2 < 0) {
		d2 += n;
	}
	return d1 < d2;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	//cin >> _;
	while (_--) {
		int k;
		cin >> n >> k;
		vector<vector<int>> b(n + 1);
		for (int i = 0; i < k; i++) {
			int x, y;
			cin >> x >> y;
			b[x].push_back(y);
		}
		for (int i = 1; i <= n; i++) {
			cur = i;
			sort(b[i].begin(), b[i].end(), cmp);
			/*cout << i << ": ";
			for (int j : b[i]) {
				cout << j << " ";
			}
			cout << endl;*/
		}
		for (int i = 1; i <= n; i++) {
			vector<vector<int>> a = b;
			map<int, int> m;
			int cnt = 0, it = i;
			int cur = 0;
			//vector<int> on;
			while (cur != k) {
				//cout << "------ " << it << endl;
				if (a[it].size()) {
					//cout << "take: " << *a[it].rbegin() << endl;
					//on.push_back(*a[it].rbegin());
					m[*a[it].rbegin()]++;
					a[it].pop_back();
				}
				//sort(on.begin(), on.end());
				/*for (int j = 0; j < on.size(); j++) {
					if (on[j] == it) {
						while (j < on.size() && on[j] == it) {
							on.erase(on.begin() + j);
						}
					}
				}*/
				/*cout << "on: ";
				for (int j : on) {
					cout << j << " ";
				}
				cout << endl;*/
				cur += m[it];
				m[it] = 0;
				cnt++;
				it = (it + 1) % n == 0 ? n : (it + 1) % n;
			}
			cout << cnt - 1 << " ";
		}
		cout << endl;
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<queue>
#include<cmath>
#include<deque>
#include<stack>
#include<iomanip>
#include<string>
#include<random>
#include<cstdio>

using namespace std;

long long cur, n;

inline bool cmp(long long a, long long b) {
	long long d1 = a - cur, d2 = b - cur;
	if (d1 < 0) {
		d1 += n;
	}
	if (d2 < 0) {
		d2 += n;
	}
	return d1 < d2;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	//cin >> _;
	while (_--) {
		long long k;
		cin >> n >> k;
		vector<vector<long long>> b(n + 1);
		for (int i = 0; i < k; i++) {
			long long x, y;
			cin >> x >> y;
			b[x].push_back(y);
		}
		for (int i = 1; i <= n; i++) {
			cur = i;
			sort(b[i].begin(), b[i].end(), cmp);
			/*cout << i << ": ";
			for (int j : b[i]) {
				cout << j << " ";
			}
			cout << endl;*/
		}
		for (int i = 1; i <= n; i++) {
			//cout << "------ " << i << endl;
			long long ans = 0;
			for (long long j = 0; j < n; j++) {
				long long it = i + j;
				if (i + j > n) {
					it -= n;
				}
				long long d = 0;
				//cout << "--- " << it << endl;
				if (b[it].size()) {
					d = b[it][0] - it;
					if (d < 0) {
						d += n;
					}
				}
				/*cout << d << " " << dist << " " << b[it].size() << endl;
				cout << n * max(0, (int)b[it].size() - 1) + d + dist << endl;*/
				ans = max(ans, n * max(0ll, (long long)b[it].size() - 1) + d + j);
			}
			cout << ans << " ";
		}
		cout << endl;
	}
}


#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<queue>
#include<cmath>
#include<deque>
#include<stack>
#include<iomanip>
#include<string>
#include<random>
#include<cstdio>

using namespace std;

long long cur, n;

inline bool cmp(long long a, long long b) {
	long long d1 = a - cur, d2 = b - cur;
	if (d1 < 0) {
		d1 += n;
	}
	if (d2 < 0) {
		d2 += n;
	}
	return d1 < d2;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int _ = 1;
	//cin >> _;
	while (_--) {
		long long k;
		cin >> n >> k;
		vector<vector<long long>> b(n + 1);
		for (int i = 0; i < k; i++) {
			long long x, y;
			cin >> x >> y;
			b[x].push_back(y);
		}
		for (int i = 1; i <= n; i++) {
			cur = i;
			sort(b[i].begin(), b[i].end(), cmp);
			/*cout << i << ": ";
			for (int j : b[i]) {
				cout << j << " ";
			}
			cout << endl;*/
		}
		for (int i = 1; i <= n; i++) {
			//cout << "------ " << i << endl;
			long long ans = 0;
			for (long long j = 0; j < n; j++) {
				long long it = i + j;
				if (i + j > n) {
					it -= n;
				}
				long long d = 0;
				//cout << "--- " << it << endl;
				if (b[it].size()) {
					d = b[it][0] - it;
					if (d < 0) {
						d += n;
					}
				}
				else {
					continue;
				}
				/*cout << d << " " << dist << " " << b[it].size() << endl;
				cout << n * max(0, (int)b[it].size() - 1) + d + dist << endl;*/
				ans = max(ans, n * max(0ll, (long long)b[it].size() - 1) + d + j);

			}
			cout << ans << " ";
		}
		cout << endl;
	}
}


#include <bits/stdc++.h>

using namespace std;
const int N=5005;
int n,m;
vector<int> adj[N];
priority_queue< pair<int,int> >pq[N];
int frq[N];
int g[N];
int d(int x,int y)
{
    return (y-x+n)%n;
}
void solve()
{
    for(int i=0;i<n;i++)
    {
        int mn=1e9;
        for(int j=0;j<adj[i].size();j++)
        {
            mn=min((((int)adj[i].size()-1)*n)+d(i,adj[i][j]),mn);
        }
        if(adj[i].size()) g[i]=mn;
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].push_back(v);
    }
    solve();
    for(int i=0;i<n;i++)
    {
        int mx=-1;
        for(int j=0;j<n;j++)
        {
            mx=max(mx,d(i,j)+g[j]);
        }
        cout<<mx<<" ";
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N=200;
int n,m;
vector<int> adj[N];
priority_queue< pair<int,int> >pq[N];
int frq[N];
int solve(int u)
{
    int t=m,ret=0;
    for(int i=0;i<n;i++)
    {
        frq[i]=0;
        while(!pq[i].empty()) pq[i].pop();
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<adj[i].size();j++)
        {
            pq[i].push({(adj[i][j]-i+n)%n,adj[i][j]});
        }
    int cur=u;
    while(1)
    {
        t-=frq[cur];
        frq[cur]=0;
        if(t==0) break;
        if(!pq[cur].empty())
        {
            frq[pq[cur].top().second]++;
            pq[cur].pop();
        }
        cur++;
        cur%=n;
        ret++;
    }
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].push_back(v);
    }
    for(int i=0;i<n;i++)
    {
        cout<<solve(i)<<" ";
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N=5005;
int n,m;
vector<long long> adj[N];
long long g[N];
long long d(int x,int y)
{
    return (y-x+n)%n;
}
void solve()
{
    for(int i=0;i<n;i++)
    {
        long long mn=1e18;
        for(int j=0;j<adj[i].size();j++)
        {
            mn=min((((int)adj[i].size()-1)*n)+d(i,adj[i][j]),mn);
        }
        if(adj[i].size()) g[i]=mn;
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].push_back(v);
    }
    solve();
    for(int i=0;i<n;i++)
    {
        long long mx=-1;
        for(int j=0;j<n;j++)
        {
            mx=max(mx,d(i,j)+g[j]);
        }
        cout<<mx<<" ";
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N=5005;
int n,m;
vector<int> adj[N];
priority_queue< pair<int,int> >pq[N];
int frq[N];
int solve(int u)
{
    int t=m,ret=0;
    for(int i=0;i<n;i++)
    {
        frq[i]=0;
        while(!pq[i].empty()) pq[i].pop();
    }
    for(int i=0;i<n;i++)
        for(int j=0;j<adj[i].size();j++)
        {
            pq[i].push({(adj[i][j]-i+n)%n,adj[i][j]});
        }
    int cur=u;
    while(1)
    {
        t-=frq[cur];
        frq[cur]=0;
        if(t==0) break;
        if(!pq[cur].empty())
        {
            frq[pq[cur].top().second]++;
            pq[cur].pop();
        }
        cur++;
        cur%=n;
        ret++;
    }
    return ret;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].push_back(v);
    }
    for(int i=0;i<n;i++)
    {
        cout<<solve(i)<<" ";
    }
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int N=5005;
int n,m;
vector<long long> adj[N];
long long g[N];
long long d(int x,int y)
{
    return (y-x+n)%n;
}
void solve()
{
    for(int i=0;i<n;i++)
    {
        long long mn=1e18;
        for(int j=0;j<adj[i].size();j++)
        {
            mn=min((((int)adj[i].size()-1)*n)+d(i,adj[i][j]),mn);
        }
        if(adj[i].size()) g[i]=mn;
    }
    return;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int u,v;
        cin>>u>>v;
        u--;v--;
        adj[u].push_back(v);
    }
    solve();
    for(int i=0;i<n;i++)
    {
        long long mx=0;
        for(int j=0;j<n;j++)
        {
            if(adj[j].size())mx=max(mx,d(i,j)+g[j]);
        }
        cout<<mx<<" ";
    }
    cout<<endl;
    return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
int __gcd(int a, int b) { return b ? __gcd(b, a%b) : a; }

using namespace std;
const int N = 100100;
int main()
{
  int i, n, a, b, j, m;
  scanf("%d %d", &n, &m);
  vector<vector<ll>> x(n + 2, vector<ll>());
  vector<ll> y(n + 2, 0);
  vector<ll> ans(n + 2, 0LL);
  for (i = 0; i < m; i++)
  {
    scanf("%d %d", &a, &b);
    x[a].push_back(b);
  }

  // precalc - time for this station
  for (i = 1; i <= n; i++)
  {
    auto sz = x[i].size();
    if (sz == 0)
      continue;
    ll mi = LLONG_MAX - 1;
    for (auto xx : x[i])
    {
      ll d = xx - (ll)i;
      while (d < 1)
        d += n;
      while (d > n)
        d -= n;
      mi = min(mi, d);
    }
    y[i] = ((ll)sz - 1LL)*(ll)n + (ll)mi;
  }
  for (i = 0; i < n; i++) // starting points
  {
    ll answ = 0;
    for (j = 0; j < n; j++) // relative from start p
    {
      int real = ((i + j) % n) + 1;
      answ = max(answ, y[real] + (ll)j);
    }
    ans[i] = answ;
  }
  for (auto j = 0; j < n - 1; j++)
    cout << ans[j] << " ";
  cout << ans[n - 1] << endl;
  return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
int __gcd(int a, int b) { return b ? __gcd(b, a%b) : a; }

using namespace std;
const int N = 100100;
int main()
{
  int i, n, a, b, j, m;
  scanf("%d %d", &n, &m);
  vector<vector<ll>> x(n + 2, vector<ll>());
  vector<ll> y(n + 2, 0);
  vector<ll> ans(n + 2, 0LL);
  for (i = 0; i < m; i++)
  {
    scanf("%d %d", &a, &b);
    x[a].push_back(b);
  }

  // precalc - time for this station
  for (i = 1; i <= n; i++)
  {
    auto sz = x[i].size();
    if (sz == 0)
      continue;
    ll mi = LLONG_MAX - 1;
    for (auto& xx : x[i])
    {
      auto d = xx - (ll)i;
      if (d < 1)
        d += n;
      mi = min(mi, d);
    }
    y[i] = ((ll)sz - 1LL)*(ll)n + (ll)mi;
  }
  for (i = 0; i < n; i++) // starting points
  {
    ll answ = 0;
    for (j = 0; j < n; j++) // relative from start p
    {
      int real = ((i + j) % n) + 1;
      answ = max(answ, y[real] + (ll)j);
    }
    ans[i] = answ;
  }
  for (auto j = 0; j < n; j++)
    printf("%I64d ", ans[j]);
  printf("\n");
  return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
int __gcd(int a, int b) { return b ? __gcd(b, a%b) : a; }

using namespace std;
const int N = 100100;
int main()
{
  int i, n, a, b, j, m;
  scanf("%d %d", &n, &m);
  vector<vector<ll>> x(n + 20000, vector<ll>());
  vector<ll> y(n + 20000, 0);
  vector<ll> ans(n + 20000, 0LL);
  for (i = 0; i < m; i++)
  {
    scanf("%d %d", &a, &b);
    x[a].push_back(b);
  }

  // precalc - time for this station
  for (i = 1; i <= n; i++)
  {
    auto sz = x[i].size();
    if (sz == 0)
      continue;
    ll mi = LLONG_MAX - 1;
    for (auto xx : x[i])
    {
      ll d = xx - (ll)i;
      while (d < 1)
        d += n;
      while (d > n)
        d -= n;
      mi = min(mi, d);
    }
    y[i] = ((ll)sz - 1LL)*(ll)n + (ll)mi;
  }
  for (i = 0; i < n; i++) // starting points
  {
    ll answ = 0;
    for (j = 0; j < n; j++) // relative from start p
    {
      int real = ((i + j) % n) + 1;
      answ = max(answ, y[real] + (ll)j);
    }
    ans[i] = answ;
  }
  for (auto j = 0; j < n - 1; j++)
    cout << ans[j] << " ";
  cout << ans[n - 1] << endl;
  return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
int __gcd(int a, int b) { return b ? __gcd(b, a%b) : a; }

using namespace std;
const int N = 100100;
int main()
{
  int i, n, a, b, j, m;
  scanf("%d %d", &n, &m);
  vector<vector<ll>> x(n + 20000, vector<ll>());
  vector<ll> y(n + 20000, 0);
  vector<ll> ans(n + 20000, 0LL);
  for (i = 0; i < m; i++)
  {
    scanf("%d %d", &a, &b);
    x[a].push_back(b);
  }

  // precalc - time for this station
  for (i = 1; i <= n; i++)
  {
    auto sz = x[i].size();
    if (sz == 0)
      continue;
    ll mi = LLONG_MAX - 1;
    for (auto xx : x[i])
    {
      ll d = xx - (ll)i;
      while (d < 1)
        d += n;
      while (d > n)
        d -= n;
      mi = min(mi, d);
    }
    y[i] = ((ll)sz - 1LL)*(ll)n + (ll)mi;
  }
  for (i = 0; i < n; i++) // starting points
  {
    ll answ = 0;
    for (j = 0; j < n; j++) // relative from start p
    {
      int real = ((i + j) % n) + 1;
      if (y[real] == 0)
        continue;
      answ = max(answ, y[real] + (ll)j);
    }
    ans[i] = answ;
  }
  for (auto j = 0; j < n - 1; j++)
    cout << ans[j] << " ";
  cout << ans[n - 1] << endl;
  return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
int __gcd(int a, int b) { return b ? __gcd(b, a%b) : a; }

using namespace std;
const int N = 100100;
int main()
{
  int i, n, a, b, j, m;
  scanf("%d %d", &n, &m);
  vector<vector<int>> x(n + 2, vector<int>());
  vector<ll> y(n + 2, 0);
  vector<ll> ans(n + 2, 0LL);
  for (i = 0; i < m; i++)
  {
    scanf("%d %d", &a, &b);
    x[a].push_back(b);
  }

  // precalc - time for this station
  for (i = 1; i <= n; i++)
  {
    auto sz = x[i].size();
    if (sz == 0)
      continue;
//    sort(x[i].begin(), x[i].end()); // min dist
    int mi = INT_MAX - 1;
    for (auto& xx : x[i])
    {
      auto dist = (n + xx - i) % n;
      mi = min(mi, dist);
    }
    y[i] = ((ll)sz - 1LL)*(ll)n + (ll)mi;
  }
  for (i = 0; i < n; i++) // starting points
  {
    ll answ = 0;
    for (j = 0; j < n; j++) // relative from start p
    {
      int real = ((i + j) % n) + 1;
      answ = max(answ, y[real] + (ll)j);
    }
    ans[i] = answ;
  }
  for (auto j = 0; j < n; j++)
    printf("%I64d ", ans[j]);
  printf("\n");
  return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
int __gcd(int a, int b) { return b ? __gcd(b, a%b) : a; }

using namespace std;
const int N = 100100;
int main()
{
  int i, n, a, b, j, m;
  scanf("%d %d", &n, &m);
  vector<vector<ll>> x(n + 2, vector<ll>());
  vector<ll> y(n + 2, 0);
  vector<ll> ans(n + 2, 0LL);
  for (i = 0; i < m; i++)
  {
    scanf("%d %d", &a, &b);
    x[a].push_back(b);
  }

  // precalc - time for this station
  for (i = 1; i <= n; i++)
  {
    auto sz = x[i].size();
    if (sz == 0)
      continue;
    ll mi = LLONG_MAX - 1;
    for (auto& xx : x[i])
    {
      auto d = xx - (ll)i;
      if (d < 1)
        d += n;
      mi = min(mi, d);
    }
    y[i] = ((ll)sz - 1LL)*(ll)n + (ll)mi;
  }
  for (i = 0; i < n; i++) // starting points
  {
    ll answ = 0;
    for (j = 0; j < n; j++) // relative from start p
    {
      int real = ((i + j) % n) + 1;
      answ = max(answ, y[real] + (ll)j);
    }
    ans[i] = answ;
  }
  for (auto j = 0; j < n - 1; j++)
    cout << ans[j] << " ";
  cout << ans[n - 1] << endl;
  return 0;
}


#include <stdio.h>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
int __gcd(int a, int b) { return b ? __gcd(b, a%b) : a; }

using namespace std;
const int N = 100100;
int main()
{
  int i, n, a, b, j, m;
  scanf("%d %d", &n, &m);
  vector<vector<int>> x(n + 2, vector<int>());
  vector<ll> y(n + 2, 0);
  vector<ll> ans(n + 2, 0LL);
  for (i = 0; i < m; i++)
  {
    scanf("%d %d", &a, &b);
    x[a].push_back(b);
  }

  // precalc - time for this station
  for (i = 1; i <= n; i++)
  {
    auto sz = x[i].size();
    if (sz == 0)
      continue;
    sort(x[i].begin(), x[i].end()); // min dist
    int mi = INT_MAX - 1;
    for (auto& xx : x[i])
    {
      auto dist = (n + xx - i) % n;
      mi = min(mi, dist);
    }
    //(ll)(((ll)n + (ll)x[i][0] - (ll)i) % n)
    y[i] = ((ll)sz - 1LL)*(ll)n + mi;
  }
  for (i = 0; i < n; i++) // starting points
  {
    ll answ = 0;
    for (j = 0; j < n; j++) // relative from start p
    {
      int real = ((i + j) % n) + 1;
      answ = max(answ, y[real] + (ll)j);
    }
    ans[i] = answ;
  }
  for (auto j = 0; j < n; j++)
    printf("%I64d ", ans[j]);
  printf("\n");
  return 0;
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<iostream>
#include<set>
#include<functional>
using namespace std;
const int maxn = 1e5 + 50;
queue<int> remain[maxn];
vector<int> fuck[maxn];
int load[maxn];
int start,n,m;
bool cmp(int a, int b)
{
	int aa = a, bb = b;
	if (aa < start)
		aa += n;
	if (bb < start)
		bb += n;
	return aa > bb;
}
int main()
{
	int i, j, k;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; i++)
	{
		scanf("%d%d", &j, &k);
		fuck[j].push_back(k);
	}
	for (int st = 1; st <= n; st++)
	{
		int cnt = 0;
		int ans = 0;
		int gowhere = st;
		for (j = 1; j <= n; j++)
		{
			start = j;
			sort(fuck[j].begin(), fuck[j].end(), cmp);
			for (k = 0; k < fuck[j].size(); k++)
			{
				remain[j].push(fuck[j][k]);
				//cout << j << " " << fuck[j][k] << endl;
			}
		}
		while (cnt < m)
		{
			cnt += load[gowhere];
			load[gowhere] = 0;
			if (cnt == m)
				break;
			if (remain[gowhere].empty())
			{
				gowhere++;
				ans++;
				if (gowhere > n)
					gowhere = 1;
				continue;
			}
			int ed = remain[gowhere].front();
			remain[gowhere].pop();
			load[ed]++;
			gowhere++;
			if (gowhere > n)
				gowhere = 1;
			ans++;
		}
		printf("%d ", ans);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<iostream>
#include<set>
#include<functional>
using namespace std;
const int maxn = 1e5 + 50;
vector<int> fuck[maxn];
int n, m;
int main()
{
	int i, j, k;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; i++)
	{
		scanf("%d%d", &j, &k);
		if (j > k)
			k += n;
		fuck[j].push_back(k);
	}
	int round = 0;
	for (i = 1; i <= n; i++)
		round = max(round, int(fuck[i].size()));
	for (int st = 1; st <= n; st++)
	{
		int max_dis = 0;
		for(i=1;i<=n;i++)
			if (fuck[i].size() == round)
			{
				int tmp_dis =0x7fffffff;
				for (j = 0; j < fuck[i].size(); j++)
				{
					if (i < st)
					{
						tmp_dis = min(tmp_dis, fuck[i][j] - st + n);
					}
					else
					{
						int dis = fuck[i][j] - st;
						tmp_dis = min(tmp_dis, dis);
					}
				}
				max_dis = max(max_dis, tmp_dis);
			}
		printf("%d ", max_dis+(round-1)*n);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<iostream>
#include<set>
#include<functional>
using namespace std;
const int maxn = 1e5 + 50;
queue<int> remain[maxn];
vector<int> fuck[maxn];
int load[maxn];
int start,n,m;
bool cmp(int a, int b)
{
	int aa = a, bb = b;
	if (aa < start)
		aa += n;
	if (bb < start)
		bb += n;
	return aa > bb;
}
int main()
{
	int i, j, k;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; i++)
	{
		scanf("%d%d", &j, &k);
		fuck[j].push_back(k);
	}
	for (int st = 1; st <= n; st++)
	{
		int cnt = 0;
		int ans = 0;
		int gowhere = st;
		for (j = 1; j <= m; j++)
		{
			start = j;
			sort(fuck[j].begin(), fuck[j].end(), cmp);
			for (k = 0; k < fuck[j].size(); k++)
			{
				remain[j].push(fuck[j][k]);
				//cout << j << " " << fuck[j][k] << endl;
			}
		}
		while (cnt < m)
		{
			cnt += load[gowhere];
			load[gowhere] = 0;
			if (cnt == m)
				break;
			if (remain[gowhere].empty())
			{
				gowhere++;
				ans++;
				if (gowhere > n)
					gowhere = 1;
				continue;
			}
			int ed = remain[gowhere].front();
			remain[gowhere].pop();
			load[ed]++;
			gowhere++;
			if (gowhere > n)
				gowhere = 1;
			ans++;
		}
		printf("%d ", ans);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<iostream>
#include<set>
#include<functional>
using namespace std;
const int maxn = 1e5 + 50;
vector<int> fuck[maxn];
int n, m;
int main()
{
	int i, j, k;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; i++)
	{
		scanf("%d%d", &j, &k);
		fuck[j].push_back(k);

	}
	int round = 0;
	for (i = 1; i <= n; i++)
		round = max(round, int(fuck[i].size()));
	for (int st = 1; st <= n; st++)
	{
		int max_dis = 0;
		for(i=1;i<=n;i++)
			if (fuck[i].size() == round)
			{
				int tmp_dis = (n + 1);
				for (j = 0; j < fuck[i].size(); j++)
				{
					if (i < st)
					{
						tmp_dis = min(tmp_dis, fuck[i][j] - st + n);
					}
					else
					{
						int dis = fuck[i][j] - st;
						if (i > fuck[i][j])
							dis += n;
						tmp_dis = min(tmp_dis, dis);
					}
				}
				max_dis = max(max_dis, tmp_dis);
			}
		printf("%d ", max_dis+(round-1)*n);
	}
}


#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<iostream>
#include<set>
#include<functional>
using namespace std;
const int maxn = 1e5 + 50;
vector<int> fuck[maxn];
int start,n,m;
bool cmp(int a, int b)
{
	int aa = a, bb = b;
	if (aa < start)
		aa += n;
	if (bb < start)
		bb += n;
	return aa > bb;
}
int main()
{
	int i, j, k;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= m; i++)
	{
		scanf("%d%d", &j, &k);
		fuck[j].push_back(k);
	}
	for (i = 1; i <= n; i++)
	{
		start = i;
		sort(fuck[i].begin(), fuck[i].end(), cmp);
	}
	for (int st = 1; st <= n; st++)
	{
		int max_dis = 0;
		for(i=1;i<=n;i++)
			if (!fuck[i].empty())
			{
				int tmp_dis =i-st;
				if (tmp_dis < 0)
					tmp_dis += n;
				int round = fuck[i].size();
				tmp_dis += (round - 1)*n;
				int ed = fuck[i][round-1];
				int dis = ed - i;
				if (dis < 0)
					dis += n;
				tmp_dis = tmp_dis + dis;
				max_dis = max(max_dis, tmp_dis);
			}
		printf("%d ", max_dis);
	}
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef  unsigned long long ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=1e6+10;
int main(){
    IO;
    int n , m ;
    cin>>n>>m ;

    auto dis=[&](int f , int t ){
        if(t>=f)return t-f;
        return n-f+t;
    };

    vector<vector<int >>vec(n+2);
    int a , b ;
    int ma=0;
    int index=1;
    int les[n+2];
    memset(les,0,sizeof(les));
    for(int i =1;i<=m;i++){
       cin>>a>>b;
       vec[a].push_back(b);
       if(vec[a].size()>ma){
           ma=vec[a].size();
           index=a;
       }
       if(les[a]==0||les[a]>dis(a,b)){
           les[a]=dis(a,b);
       }
    }
    int last[n+2];
    int start=index+1;
    if(start==n+1)start=1;
    for(int i =1;i<=n;i++){
        last[start]=index;
        if(vec[start].size()==ma)index = start;
        start++;
        if(start==n+1)start=1;
    }
    int reff=(ma-1)*n;
    for(int i = 1 ; i<=n;i++){
        int ans= 0 ;
        for(int j = 1 ; j<=n ; j++){
            if(vec[j].size()==ma){
                ans=max(ans,dis(i,j)+les[j]);
            }
        }
        cout<<reff+ans<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef  unsigned long long ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=1e6+10;
int main(){
    IO;
    int n , m ;
    cin>>n>>m ;
    auto dis=[&](int f , int t ){
        if(t>=f)return t-f;
        return n-f+t;
    };
    vector<vector<int >>vec(n+2);
    int a , b ;
    int ma=0;
    int les[n+2];
    memset(les,0,sizeof(les));
    for(int i =1;i<=m;i++){
       cin>>a>>b;
       vec[a].push_back(b);
       if(vec[a].size()>ma){
           ma=vec[a].size();
       }
       if(les[a]==0||les[a]>dis(a,b)){
           les[a]=dis(a,b);
       }
    }
    int cost[n+2];
    for(int i = 1 ; i<=n;i++){
        if(vec[i].size()==0){
            cost[i]=0;
            continue;
        }
        cost[i]=(vec[i].size()-1)*n+les[i];
    }
    int ans[n+2];
    for(int i = 1;i<=n;i++){
        int step=0;
        int ansHere=0;
        int start=i;
        for(int j = 1 ;j<=n ; j++){

            ansHere=max(ansHere,(cost[start]==0?0:step+cost[start]));
            step++;
            start++;
            if(start==n+1)start=1;
        }
        ans[i]=ansHere;
        cout<<ansHere<<" ";
    }

    return 0;
}
// 7 10 9 8 8


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef  unsigned long long ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=1e6+10;
int main(){
    IO;
    int n , m ;
    cin>>n>>m ;
    vector<vector<int >>vec(n+2);
    int a , b ;
    int ma=0;
    int index=1;
    int les[n+2];
    memset(les,0,sizeof(les));
    for(int i =1;i<=m;i++){
       cin>>a>>b;
       vec[a].push_back(b);
       if(vec[a].size()>ma){
           ma=vec[a].size();
           index=a;
       }
       if(les[a]==0||les[a]>b){
           les[a]=b;
       }
    }
    int last[n+2];
    int start=index+1;
    if(start==n+1)start=1;
    for(int i =1;i<=n;i++){
        last[start]=index;
        if(vec[start].size()==ma)index = start;
        start++;
        if(start==n+1)start=1;
    }
    int reff=(ma-1)*n;
    auto dis=[&](int f , int t ){
        if(t>=f)return t-f;
        return n-f+t;
    };
    for(int i = 1 ; i<=n;i++){
        int ans= 0 ;
        for(int j = 1 ; j<=n ; j++){
            if(vec[j].size()==ma){
                ans=max(ans,dis(i,j)+dis(j,les[j]));
            }
        }
        cout<<reff+ans<<" ";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef  unsigned long long ull;
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=1e6+10;
int main(){
    IO;
    int n , m ;
    cin>>n>>m ;
    vector<vector<int >>vec(n+2);
    int a , b ;
    int ma=0;
    int index=1;
    for(int i =1;i<=m;i++){
       cin>>a>>b;
       vec[a].push_back(b);
       if(vec[a].size()>ma){
           ma=vec[a].size();
           index=a;
       }
    }
    int last[n+2];
    int start=index+1;
    if(start==n+1)start=1;
    for(int i =1;i<=n;i++){
        last[start]=index;
        if(vec[start].size()==ma)index = start;
        start++;
        if(start==n+1)start=1;
    }
    int reff=(ma-1)*n;
    int minNum[n+2];
    auto dis=[&](int f , int t ){
        if(t>=f)return t-f;
        return n-f+t;
    };
    for(int i = 1 ;i<=n;i++){
        int less=INT_MAX;
        for(int num : vec[i])less=min(less,dis(i,num));
        minNum[i]=less;
    }
    for(int i = 1 ; i<=n;i++){
        cout<<reff+minNum[last[i]]+dis(i,last[i])<<" ";
    }
    return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> dis(n + 1, n), cnt(n + 1, -1);
	while (m--) {
		int a, b;
		cin >> a >> b;
		++cnt[a];
		dis[a] = min(dis[a], a < b : b - a : b - a + n);
	}
	for (int i = 1; i <= n; ++i) {
		int res = 0;
		for (int j = 1; j <= n; ++j)
			res = max(res, (i < j ? j - i : j - i + n) + cnt[j] * n + dis[j]);
		cout << res << ' ';
	}
	cout << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> dis(n + 1, 0), cnt(n + 1, 0);
	while (m--) {
		int a, b;
		cin >> a >> b;
		++cnt[a];
		dis[a] = min(dis[a], a > b ? b - a : b - a - n);
	}
	vector<int> pre(n, -n), suf(n + 2, -n);
	for (int i = 1; i != n; ++i) {
		pre[i] = pre[i - 1];
		if (cnt[i]) pre[i] = max(pre[i], cnt[i] * n + dis[i] + i);
	}
	for (int i = n; i; --i) {
		suf[i] = suf[i + 1];
		if (cnt[i]) suf[i] = max(suf[i], cnt[i] * n + dis[i] + i);
	}
	for (int i = 1; i <= n; ++i)
		cout << max(pre[i - 1] + n - i, suf[i] - i) << ' ';
	cout << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> dis(n + 1, n), cnt(n + 1, -1);
	while (m--) {
		int a, b;
		cin >> a >> b;
		++cnt[a];
		dis[a] = min(dis[a], a < b ? b - a : b - a + n);
	}
	for (int i = 1; i <= n; ++i) {
		int res = 0;
		for (int j = 1; j <= n; ++j)
			res = max(res, (i < j ? j - i : j - i + n) + cnt[j] * n + dis[j]);
		cout << res << ' ';
	}
	cout << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> dis(n + 1, n), cnt(n + 1, -1);
	while (m--) {
		int a, b;
		cin >> a >> b;
		++cnt[a];
		dis[a] = min(dis[a], a > b ? b - a + n : b - a);
	}
	for (int i = 1; i <= n; ++i) {
		int res = 0;
		for (int j = 1; j <= n; ++j)
			res = max(res, (i > j ? j - i + n : j - i) + cnt[j] * n + dis[j]);
		cout << res << ' ';
	}
	cout << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> dis(n), cnt(n, 0);
	while (m--) {
		int a, b;
		cin >> a >> b;
		int d = --a < --b ? b - a : b + n - a;
		dis[a] = cnt[a]++ ? min(dis[a], d) : d;
	}
	for (int i = 0; i != n; ++i) {
		int res = 0;
		for (int j = 0; j != n; ++j) if (cnt[j]) res = max(res, j - i + (j < i ? n : 0) + (cnt[j] - 1) * n + dis[j]);
		cout << res << ' ';
	}
	cout << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> dis(n + 1, 0), cnt(n + 1, 0);
	while (m--) {
		int a, b;
		cin >> a >> b;
		++cnt[a];
		dis[a] = min(dis[a], a > b ? b - a : b - a - n);
	}
	vector<int> pre(n, 0), suf(n + 2, 0);
	for (int i = 1; i != n; ++i) {
		pre[i] = pre[i - 1];
		if (cnt[i]) pre[i] = max(pre[i], cnt[i] * n + dis[i] + i);
	}
	for (int i = n; i; --i) {
		suf[i] = suf[i + 1];
		if (cnt[i]) suf[i] = max(suf[i], cnt[i] * n + dis[i] + i);
	}
	for (int i = 1; i <= n; ++i) {
		cout << max(pre[i - 1] + n - i, suf[i] - i) << ' ';
	}
	cout << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> dis(n + 1, 0), cnt(n + 1, 0);
	while (m--) {
		int a, b;
		cin >> a >> b;
		++cnt[a];
		dis[a] = min(dis[a], a > b ? b - a : b - a - n);
	}
	for (int i = 1; i <= n; ++i) {
		int res = 0;
		for (int j = 1; j <= n; ++j) if (cnt[j])
			res = max(res, (i > j ? j - i + n : j - i) + cnt[j] * n + dis[j]);
		cout << res << ' ';
	}
	cout << endl;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> dis(n + 1, n), cnt(n + 1, -1);
	while (m--) {
		int a, b;
		cin >> a >> b;
		++cnt[a];
		dis[a] = min(dis[a], a > b ? b - a + n : b - a);
	}
	for (int i = 1; i <= n; ++i) {
		int res = 0;
		for (int j = 1; j <= n; ++j) if (~cnt[j])
			res = max(res, (i > j ? j - i + n : j - i) + cnt[j] * n + dis[j]);
		cout << res << ' ';
	}
	cout << endl;
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define int int64_t
#define double long double
#define pii pair<int, int>
#define pdd pair<double, double>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define endl "\n"
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int32_t main(){
   ios_base :: sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   int n, m;
   cin >> n >> m;
   vector<int> ar[n + 1];
   for(int i = 0; i < m; i ++){
      int a, b;
      cin >> a >> b;
      ar[a].pb(b);
   }
   vector<vector<int>> d(n + 1, vector<int>(n + 1));
   for(int i = 1; i <= n; i ++){
      int c = 1;
      for(int j = (i == n ? 1 : i + 1); j != i; j ++, c ++){
         d[i][j] = c;
         j %= n;
      }
   }
   for(int i = 1; i <= n; i ++)
   sort(ar[i].begin(), ar[i].end(), [&](int a, int b){
            return d[i][a] > d[i][b];
        });
   vector<int> res(n + 1);
   for(int i = 1; i <= n; i ++){
      if(!ar[i].empty())
         res[i] = (ar[i].size() - 1) * n + d[i][ar[i].back()];
   }
   for(int i = 1; i <= n; i ++){
      int ans = res[i];
      for(int j = 1; j <= n; j ++)
         if(res[j]) ans = max(ans, res[j] + d[i][j]);
      cout << ans << " ";
   }
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define int int64_t
#define double long double
#define pii pair<int, int>
#define pdd pair<double, double>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define endl "\n"
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int32_t main(){
   ios_base :: sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   int n, m;
   cin >> n >> m;
   vector<int> ar[n + 1];
   for(int i = 0; i < m; i ++){
      int a, b;
      cin >> a >> b;
      ar[a].pb(b);
   }
   vector<vector<int>> d(n + 1, vector<int>(n + 1));
   for(int i = 1; i <= n; i ++){
      int c = 1;
      for(int j = (i == n ? 1 : i + 1); j != i; j ++, c ++){
         d[i][j] = c;
         j %= n;
      }
   }
   for(int i = 1; i <= n; i ++)
   sort(ar[i].begin(), ar[i].end(), [&](int a, int b){
            return d[i][a] > d[i][b];
        });
   vector<int> res(n + 1);
   for(int i = 1; i <= n; i ++){
      if(!ar[i].empty())
         res[i] = (ar[i].size() - 1) * n + d[i][ar[i].back()];
   }
   for(int i = 1; i <= n; i ++){
      int ans = res[i], c = 1;
      for(int j = (i == n ? 1 : i + 1); j != i; j ++, c ++){
         ans = max(ans, res[j] + c);
         j %= n;
      }
      cout << ans << " ";
   }
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define int int64_t
#define double long double
#define pii pair<int, int>
#define pdd pair<double, double>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define endl "\n"
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int32_t main(){
   ios_base :: sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   int n, m;
   cin >> n >> m;
   vector<int> ar[n + 1];
   for(int i = 0; i < m; i ++){
      int a, b;
      cin >> a >> b;
      ar[a].pb(b);
   }
   for(int i = 1; i <= n; i ++)
   sort(ar[i].begin(), ar[i].end(), [&](int a, int b){
            int qa = (a >= i ? a - i : (abs(i - n) + a));
            int qb = (b >= i ? b - i : (abs(i - n) + b));
            return qa > qb;
        });
   vector<int> res(n + 1);
   for(int i = 1; i <= n; i ++){
      if(!ar[i].empty())
         res[i] = (ar[i].size() - 1) * n + (ar[i].back() >= i ? ar[i].back() - i : (abs(i - n) + ar[i].back()));
   }
   for(int i = 1; i <= n; i ++){
      int ans = res[i];
      for(int j = i + 1; j <= n; j ++)
         ans = max(ans, res[j] + j - i);
      for(int j = i - 1; j >= 1; j --)
         ans = max(ans, res[j] + n - (i - j));
      cout << ans << " ";
   }
}


//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#define int int64_t
#define double long double
#define pii pair<int, int>
#define pdd pair<double, double>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define endl "\n"
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

int32_t main(){
   ios_base :: sync_with_stdio(0);
   cin.tie(0); cout.tie(0);
   int n, m;
   cin >> n >> m;
   vector<int> ar[n + 1];
   for(int i = 0; i < m; i ++){
      int a, b;
      cin >> a >> b;
      ar[a].pb(b);
   }
   for(int i = 1; i <= n; i ++)
   sort(ar[i].begin(), ar[i].end(), [&](int a, int b){
            int qa = (a >= i ? a - i : (abs(i - n) + a));
            int qb = (b >= i ? b - i : (abs(i - n) + b));
            return qa > qb;
        });
   vector<int> res(n + 1);
   for(int i = 1; i <= n; i ++){
      if(!ar[i].empty())
         res[i] = (ar[i].size() - 1) * n + (ar[i].back() >= i ? ar[i].back() - i : (abs(i - n) + ar[i].back()));
   }
   for(int i = 1; i <= n; i ++){
      int ans = res[i], c = 1;
      for(int j = (i == n ? 1 : i + 1); j != i; j ++, c ++){
         ans = max(ans, res[j] + c);
         j %= n;
      }
      cout << ans << " ";
   }
}


#include <stdlib.h>
#include <stdio.h>
#include <iostream>

using namespace std;

 int main() {

int c;
int f=0;
int a=0;
int b=0;
int x=0;
int y=0;
cin >> c;
int *A= new int [c];

for (int i=0; i<c; i++){

	cin>>x>>y>>a>>b;
	f=0;
	while(x!=y){

		x+=a;
		y-=b;
		f++;
		if(x>y){
		f=-1;
		break;}
	}
//	cout<<f;
A[i]=f;

	}

	for(int i=0; i<c; i++)
	cout<<A[i]<<endl;

	system("PAUSE");
	return 0;
	}


#include <stdlib.h>
#include <stdio.h>
#include <iostream>

using namespace std;

main() {

int c;
int f=0;
int a,b,x,y;
cin >> c;
int *A= new int [c];

for (int i=0; i<c; i++){

	cin>>x>>y>>a>>b;

	while(x!=y){
		x+=a;
		y-=b;
		f++;
		if(x>y){
		f=-1;
		break;}
	}
A[i]=f;
//cout<<A[i];
	}

	for(int i=0; i<c; i++)
	cout<<A[i]<<endl;

	system("PAUSE");
	return 0;
	}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,a,b;
    int t;
    int temp,ans,sum;
    cin>>t;
    while(t--)
    {
        cin>>x>>y>>a>>b;
        temp=y-x;
        sum=a+b;
        ans=temp/sum;
        if(ans==ceil(ans)||ans==floor(ans))
        {
            cout<<ans<<endl;
        }
        else
        {
            cout<<"-1"<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,a,b;
    int t;
    int temp,ans,sum,spa;
    cin>>t;
    while(t--)
    {
        cin>>x>>y>>a>>b;
        temp=y-x;
        sum=a+b;
        ans=temp/sum;
        if(temp%sum==0)
        {
            cout<<ans;
        }
        else
        {
            cout<<"-1";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,a,b;
    int t;
    int temp,ans,sum,spa;
    while(t--)
    {
        cin>>x>>y>>a>>b;
        temp=y-x;
        sum=a+b;
        ans=temp/sum;
        if(temp%sum==0)
        {
            cout<<ans;
        }
        else
        {
            cout<<"-1";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,a,b;
    int t;
    int temp,ans,sum;
    cin>>t;
    while(t--)
    {
        cin>>x>>y>>a>>b;
        temp=y-x;
        sum=a+b;
        ans=temp/sum;
        if(ans==ceil(ans))
        {
            cout<<ans;
        }
        else
        {
            cout<<"-1";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,a,b;
    int t;
    int temp,ans,sum;
    cin>>t;
    while(t--)
    {
        cin>>x>>y>>a>>b;
        temp=y-x;
        sum=a+b;
        ans=temp/sum;
        if(temp%sum==0)
        {
            cout<<ans;
        }
        else if(temp%sum)
        {
            cout<<"-1";
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int x,y,a,b;
    int t;
    int temp,ans,sum;
    cin>>t;
    while(t--)
    {
        cin>>x>>y>>a>>b;
        temp=y-x;
        sum=a+b;
        ans=temp/sum;
        if(temp%sum==0)
        {
            cout<<ans<<endl;
        }
        else
        {
            cout<<"-1"<<endl;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int x,y,a ,b,sum =0,count=0;
		cin >> x>>y>> a>>b;
		while(x<=y){
			x+=a;
			y-=b;
			sum++;
		}
		if(x-a==y+b){
			count++;
		}
		if(count ==1) cout <<sum-1<<endl;
		else cout <<"-1"<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		int x,y,a ,b;
		cin >> x>>y>> a>>b;
		int sum = (y-x)/(a+b);
		if((y-x)%(a+b)==0){
			cout <<sum<<endl;
		}
		else cout <<"-1"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		double x,y,a ,b,sum =0,count=0;
		cin >> x>>y>> a>>b;
		if((y-x)/(a+b)==(int)((y-x)/(a+b))){
			cout <<(y-x)/(a+b)<<endl;
		}
		else cout <<"-1"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n;i++){
		double x,y,a ,b;
		cin >> x>>y>> a>>b;
		double sum = (y-x)/(a+b)*1.0;
		if(sum==(int)(sum)){
			cout <<sum<<endl;
		}
		else cout <<"-1"<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
    int x,y,a,b,i,p,q,t;
    cin>>t;
    while(t++)
    {
        cin>>x>>y>>a>>b;
        p=y-x;
        q=a+b;
        if(p%q==0)printf("%d\n",p/q);
        else printf("-1");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
   long long int x,y,a,b,i,p,q,t;
    cin>>t;
    while(t--)
    {
        cin>>x>>y>>a>>b;
        p=y-x;
        q=a+b;
        if(p%q==0)printf("%lld\n",p/q);
        else printf("-1");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
   long long int x,y,a,b,i,p,q,t;
    cin>>t;
    while(t++)
    {
        cin>>x>>y>>a>>b;
        p=y-x;
        q=a+b;
        if(p%q==0)printf("%lld\n",p/q);
        else printf("-1");
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main ()
{
   long long int x,y,a,b,i,p,q,t;
    cin>>t;
    while(t--)
    {
        cin>>x>>y>>a>>b;
        p=y-x;
        q=a+b;
        if(p%q==0)printf("%lld\n",p/q);
        else printf("-1\n");
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define lld long long int
#define ld long int
#define fl float
#define dl double dl
#define vi vector<int>
#define vs vector<string>
#define stki stack<int>
#define stks stack<string>
#define qi queue<int>
#define pqi priority_queue<int>
#define seti set<int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define forn for(int i=0; i<n; i++)
#define el endl
#define str string
#define si(a) scanf("%d" , &a)
#define sl(a) scanf("%lld" , &a)
#define sii(a,b) scanf("%d %d" , &a , &b)
#define siii(a,b,c) scanf("%d %d %d" , &a , &b, &c)
#define sll(a,b) scanf("%lld %lld" , &a , &b)
#define slll(a,b,c) scanf("%lld %lld %lld" , &a , &b, &c)

int a[500], b[500];

int main()
{
	lld x,y,j,t,a,b, i,flag=0;
	cin>>t;
	for(i=1; i<=t; i++){
		cin>>x>>y>>a>>b;
		for(j=1; j<y; j++){
			x=x+a;
			y=y-b;
			if(x==y){
				flag=1;
				break;
			}
		}
		if(flag==1){
			cout<<j<<endl;
		} else{
			cout<<-1<<endl;
		}
		flag=0;
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define lld long long int
#define ld long int
#define fl float
#define dl double dl
#define vi vector<int>
#define vs vector<string>
#define stki stack<int>
#define stks stack<string>
#define qi queue<int>
#define pqi priority_queue<int>
#define seti set<int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define forn for(int i=0; i<n; i++)
#define el endl
#define str string
#define si(a) scanf("%d" , &a)
#define sl(a) scanf("%lld" , &a)
#define sii(a,b) scanf("%d %d" , &a , &b)
#define siii(a,b,c) scanf("%d %d %d" , &a , &b, &c)
#define sll(a,b) scanf("%lld %lld" , &a , &b)
#define slll(a,b,c) scanf("%lld %lld %lld" , &a , &b, &c)

int a[500], b[500];

int main()
{
	lld x,y,j,t,a,b, i,flag=0, f;
	cin>>t;
	for(i=1; i<=t; i++){
		cin>>x>>y>>a>>b;
		f=(x+y)/2+1;
		for(j=1; x<=y && y>=x; j++){
			x=x+a;
			y=y-b;
			if(x==y){
				flag=1;
				break;
			}
		}
		if(flag==1){
			cout<<j<<endl;
		} else{
			cout<<-1<<endl;
		}
		flag=0;
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define lld long long int
#define ld long int
#define fl float
#define dl double dl
#define vi vector<int>
#define vs vector<string>
#define stki stack<int>
#define stks stack<string>
#define qi queue<int>
#define pqi priority_queue<int>
#define seti set<int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define forn for(int i=0; i<n; i++)
#define el endl
#define str string
#define si(a) scanf("%d" , &a)
#define sl(a) scanf("%lld" , &a)
#define sii(a,b) scanf("%d %d" , &a , &b)
#define siii(a,b,c) scanf("%d %d %d" , &a , &b, &c)
#define sll(a,b) scanf("%lld %lld" , &a , &b)
#define slll(a,b,c) scanf("%lld %lld %lld" , &a , &b, &c)

int a[500], b[500];

int main()
{
	lld x,y,j,t,a,b, i,pos_differ,how_far;
	cin>>t;
	for(i=1; i<=t; i++){
		cin>>x>>y>>a>>b;
		pos_differ=y-x;
		how_far=a+b;

		if(pos_differ%how_far==0){
			cout<<pos_differ/how_far<<endl;
		} else{
			cout<<-1<<endl;
		}
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define lld long long int
#define ld long int
#define fl float
#define dl double dl
#define vi vector<int>
#define vs vector<string>
#define stki stack<int>
#define stks stack<string>
#define qi queue<int>
#define pqi priority_queue<int>
#define seti set<int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define forn for(int i=0; i<n; i++)
#define el endl
#define str string
#define si(a) scanf("%d" , &a)
#define sl(a) scanf("%lld" , &a)
#define sii(a,b) scanf("%d %d" , &a , &b)
#define siii(a,b,c) scanf("%d %d %d" , &a , &b, &c)
#define sll(a,b) scanf("%lld %lld" , &a , &b)
#define slll(a,b,c) scanf("%lld %lld %lld" , &a , &b, &c)

int a[500], b[500];

int main()
{
	lld x,y,j,t,a,b, i,flag=0, f;
	cin>>t;
	for(i=1; i<=t; i++){
		cin>>x>>y>>a>>b;
		f=(x+y)/2+1;
		for(j=1; x<=f || y>=f; j++){
			x=x+a;
			y=y-b;
			if(x==y){
				flag=1;
				break;
			}
		}
		if(flag==1){
			cout<<j<<endl;
		} else{
			cout<<-1<<endl;
		}
		flag=0;
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define lld long long int
#define ld long int
#define fl float
#define dl double dl
#define vi vector<int>
#define vs vector<string>
#define stki stack<int>
#define stks stack<string>
#define qi queue<int>
#define pqi priority_queue<int>
#define seti set<int>
#define pb push_back
#define pf push_front
#define mp make_pair
#define forn for(int i=0; i<n; i++)
#define el endl
#define str string
#define si(a) scanf("%d" , &a)
#define sl(a) scanf("%lld" , &a)
#define sii(a,b) scanf("%d %d" , &a , &b)
#define siii(a,b,c) scanf("%d %d %d" , &a , &b, &c)
#define sll(a,b) scanf("%lld %lld" , &a , &b)
#define slll(a,b,c) scanf("%lld %lld %lld" , &a , &b, &c)

int a[500], b[500];

int main()
{
	lld x,y,j,t,a,b, i,flag=0, f;
	cin>>t;
	for(i=1; i<=t; i++){
		cin>>x>>y>>a>>b;
		f=(x+y)/2+1;
		for(j=1; x<=f; j++){
			x=x+a;
			y=y-b;
			if(x==y){
				flag=1;
				break;
			}
		}
		if(flag==1){
			cout<<j<<endl;
		} else{
			cout<<-1<<endl;
		}
		flag=0;
	}

	return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
template <typename Tp> void read(Tp &num) {
  num = 0;
  char c = getchar();
  int f = -1;
  while (!isdigit(c))
    c == '-' ? f = -1 : 1, c = getchar();
  while (isdigit(c))
    num = (num << 3) + (num << 1) + (c ^ 48), c = getchar();
  num *= f;
}
template <typename Tp, typename... etc> void read(Tp &num, etc &... more) {
  read(num);
  read(more...);
}
int t,x,y,a,b;
int main() {
  read(t);
  while (t--) {
    read(x, y, a, b);
    if((x+y)%(a+b))
      printf("-1\n");
    else printf("%d\n", (x + y) / (a + b));
  }
}


#include<iostream>
#include<cstdio>
using namespace std;
template <typename Tp> void read(Tp &num) {
  num = 0;
  char c = getchar();
  int f = -1;
  while (!isdigit(c))
    c == '-' ? f = -1 : 1, c = getchar();
  while (isdigit(c))
    num = (num << 3) + (num << 1) + (c ^ 48), c = getchar();
  num *= f;
}
template <typename Tp, typename... etc> void read(Tp &num, etc &... more) {
  read(num);
  read(more...);
}
int t,x,y,a,b;
int main() {
  cin>>t;
  while (t--) {
    cin>>x>>y>>a>>b;
    if((x+y)%(a+b))
      printf("-1\n");
    else printf("%d\n", (x + y) / (a + b));
  }
}


#include<iostream>
#include<cstdio>
using namespace std;
template <typename Tp> void read(Tp &num) {
  num = 0;
  char c = getchar();
  int f = -1;
  while (!isdigit(c))
    c == '-' ? f = -1 : 1, c = getchar();
  while (isdigit(c))
    num = (num << 3) + (num << 1) + (c ^ 48), c = getchar();
  num *= f;
}
template <typename Tp, typename... etc> void read(Tp &num, etc &... more) {
  read(num);
  read(more...);
}
int t,x,y,a,b;
int main() {
  cin >> t;
  while (t--) {
    cin >> x >> y >> a >> b;
    if(abs(x-y)%(a+b))
      printf("-1\n");
    else printf("%d\n", abs(x - y) / (a + b));
  }
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000

using namespace std;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		ll rt = 0;
		ll x, y, a, b;
		cin >> x >> y >> a >> b;
		for(ll i = 0; x!=y && y > 0; i++){
			x += a;
			y -= b;
			rt++;
			if(x == y){
				break;
			}
		}
		if(x == y) cout << rt << "\n";

		else cout << -1 << "\n";
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000

using namespace std;

void func(){
	int rt = 0;
		ll x, y, a, b;
		cin >> x >> y >> a >> b;
		while(y > 0){
			x += a;
			y -= b;
			rt++;
			if(x == y || x > y){
				break;
			}
		}
		if(x == y) cout << rt << "\n";

		else cout << -1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		func();
	}

	return 0;
}


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

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
using namespace std;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll t = 1, x, y, a, b, t1;
	cin >> t;
	while(t--){
		cin >> x >> y >> a >> b;

		t1 = y-x;

		if(t1 % (a+b)) cout << "-1\n";
		else{
			cout << t1 / (a+b) << "\n";
		}

	}

	return 0;
}


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

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
using namespace std;

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	ll t = 1, x, y, a, b, t1;
	cin >> t;
	while(t--){
		cin >> x >> y >> a >> b;

		t1 = y-x;

		if(t1 <= a || t1 <= b) cout << "-1\n";
		else if(a == b && t1 % a != 0) cout << "-1\n";
		else{
			cout << t1 / (a+b) << "\n";
		}

	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000

using namespace std;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		ll rt = 0;
		ll x, y, a, b;
		cin >> x >> y >> a >> b;
		while(y != x && y > 0){
			x += a;
			y -= b;
			rt++;
			if(x == y){
				break;
			}
		}
		if(x == y){
			cout << rt << "\n";
		}
		else{
			cout << -1 << "\n";
		}
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000

using namespace std;

void func(){
	int rt = 0;
		ll x, y, a, b;
		cin >> x >> y >> a >> b;
		for(int i = 0; y > 0; i++){
			x += a;
			y -= b;
			rt++;
			if(x == y){
				break;
			}
		}
		if(x == y) cout << rt << "\n";

		else cout << -1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		func();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000

using namespace std;

void func(){
	int rt = 0;
		ll x, y, a, b;
		cin >> x >> y >> a >> b;
		for(int i = 0; y > 0; i++){
			x += a;
			y -= b;
			rt++;
			if(x == y || x > y){
				break;
			}
		}
		if(x == y) cout << rt << "\n";

		else cout << -1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		func();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000

using namespace std;

void func(){
	int rt = 0;
		ll x, y, a, b;
		cin >> x >> y >> a >> b;
		for(int i = 0; x!=y && y > 0; i++){
			x += a;
			y -= b;
			rt++;
			if(x == y){
				break;
			}
		}
		if(x == y) cout << rt << "\n";

		else cout << -1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		func();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000

using namespace std;

void func(){
	int rt = 0, dec = 0;
		ll x, y, a, b;
		cin >> x >> y >> a >> b;

		while(y > 0){
			x += b;
			y -= a;
			rt++;
			if(x == y){
				dec++;
				break;
			}
		}
		if(dec) cout << rt << "\n";

		else cout << -1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		func();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000

using namespace std;

void func(){
	int rt = 0, dec = 0;
		ll x, y, a, b;
		cin >> x >> y >> a >> b;

		while(y > x){
			x += b+a;
			rt++;
			if(x == y){
				dec++;
				break;
			}
		}
		if(dec) cout << rt << "\n";

		else cout << -1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		func();
	}

	return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define vi vector <int>
#define vll vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>
#define F first
#define S second
#define INF 1000000000000000000
#define pi atan(1)*4
#define MOD 1000000000+7L
#define eps 0.0000006
#define MAX_V 10000

using namespace std;

void func(){
	int rt = 0, dec = 0;
		ll x, y, a, b;
		cin >> x >> y >> a >> b;
		if(x > 100 & y > 100){
			x /= 10;
			y /= 10;
		}

		while(y > 0){
			x += a;
			y -= b;
			rt++;
			if(x == y){
				dec++;
				break;
			}
		}
		if(x > 100 & y > 100){
			cout << rt * 10 << "\n";
		}
		else if(dec ) cout << rt << "\n";

		else cout << -1 << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int t;
	cin >> t;
	while(t--){
		func();
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,ans=0,a,b,x,y,s;
    cin>>n;
    while(n--){
        cin>>x>>y>>a>>b;
        s=y-x;
        if(s%(a+b)!=0){
        	cout<<-1<<endl;
        	continue;
		}
		cout<<s/(a+b)<<endl;
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
inline int read(){
	int f=1,res=0;char c=getchar();
	while(c<'0'||c>'9') {if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){res=res*10+c-'0',c=getchar();}
	return f*res;
}
int t,x,y,a,b;
int main(){
	t=read();
	while(t--){
		x=read();y=read();a=read();b=read();
		int len=y-x;
		if(len%(a+b)==0) printf("%d\n",len/(a+b));
		else printf("-1\n");
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <map>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

int q;
int main() {
	cin >> q;
	for (int i = 1; i <= q; i++) {
		int x, y, a, b;
		cin >> x >> y >> a >> b;
		int dis = y - x;
		int t = dis / (a + b);
		if (dis % (a + b) == 0) cout << t << endl;
		else cout << -1 << endl;
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,a,b,c,d;
int main()
{
	cin>>t;
	while(t--){
		scanf("%d%d%d%d",&a,&b,&c,&d);
		(b-a)%(c+d)?printf("-1\n"):printf("%d\n",(b-a)/(c+d));
	}
}


#include<iostream>
using namespace std;
int main() {
    int t, x, y, a, b;
    cin >> t;
    for (int i = 0; i < t; i++) {
        cin >> x >> y >> a >> b;
        if ((y - x) % (a + b) == 0) cout << (y - x) / (a + b) << endl;
        else cout << "-1\n";
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,x,y;
  cin>>a>>b;
  cin>>x>>y;
  if((b-a)%(x+y)==0)
  {
  	cout<<(b-a)/(x-y)<<endl;
  }
  else
  {
  	cout<<-1<<endl;
  }
  return 0;
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include <bits/stdc++.h>
using namespace std;
template<typename T>inline void read(T &FF){
	T RR=1;FF=0;char CH=getchar();
	for(;!isdigit(CH);CH=getchar())if(CH=='-')RR=-1;
	for(;isdigit(CH);CH=getchar())FF=(FF<<1)+(FF<<3)+(CH^48);
	FF*=RR;
}
template<typename T>void write(T x){
	if(x<0)putchar('-'),x*=-1;
	if(x>9)write(x/10);
	putchar(x%10+48);
}
int main(){
	int T;
	read(T);
	while(T--){
		int x,y,a,b;
		read(x);read(y);read(a);read(b);
		if((y-x)%(a+b)!=0)puts("-1");
		else write((y-x)/(a+b)),puts("");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t;
long long x,y,a,b;
int main()
{
     //freopen("","r",stdin);
     //freopen("","w",stdout);
	 scanf("%d",&t);
	 while(t--)
	 {
	 	 scanf("%lld%lld%lld%lld",&x,&y,&a,&b);
	 	 x=y-x,a=a+b;
	 	 if(x%a==0) printf("%lld\n",x/a);
	 	 else printf("-1\n");
	 }
     //fclose(stdin);
     //fclose(stdout);
     return 0;
}


#include<bits/stdc++.h>
using namespace std;
int s,n,m,a,b,c,d;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a>>b>>c>>d;
		s=0;
		while(a<b){
			a+=c;
			b-=d;
			s++;
		}
		if(a==b) cout<<s<<endl;
		else cout<<"-1"<<endl;
	}
	return 0;
}


#include <iostream>
using namespace std;
int main()
{
    int t,a,b,x,y;
    cin>>t;
    while (t--)
    {
        cin>>x>>y>>a>>b;
        if ((y-x)%(a+b))
        {
            cout<<"-1"<<endl;
        }
        else
        {
            cout<<(y-x)/(a+b)<<endl;
        }
    }
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
#define MAXN 50005
#define INF 0x3f3f3f3f
#define lovelive long long int
inline int homax(int a,int b)
{
    if(a > b) return a;
    return b;
}
inline int homin(int a,int b)
{
    if(a > b) return b;
    return a;
}
using namespace std;
int main()
{
    int T;
    cin >> T;
    while(T--)
    {
        lovelive X,Y,A,B;
        cin >> X  >> Y >> A >> B;
        if((Y-X) % (A+B) == 0)
        {
            cout << (Y-X) / (A+B) << endl;
        }else{
            cout << -1 << endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int t,x,y,a,b;
int main(){
    cin>>t;
    for(int i=1;i<=t;i++){
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0)cout<<(y-x)/(a+b)<<endl;
        else cout<<-1<<endl;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int t,x,y,a,b;
int main(){
	cin>>t;
	while(t--){
		cin>>x>>y>>a>>b;
		if((y-x)%(a+b)==0)
			cout<<(y-x)/(a+b)<<endl;
		else
			cout<<-1<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,x,a,y,b;
int main() {
 scanf("%d",&t);
 while(t--) {
  scanf("%d %d %d %d",&x,&y,&a,&b);
  if((y-x)%(a+b)==0)
   printf("%d\n",(y-x)/(a+b));
  else
   puts("-1");
 }
}


#include<bits/stdc++.h>
using namespace std;
int t,x,y,a,b;
int main()
{
	cin>>t;
	for(int i=1;i<=t;++i)
	{
		cin>>x>>y>>a>>b;
		if((y-x)%(a+b)==0)
			cout<<(y-x)/(a+b)<<endl;
		else
			cout<<-1<<endl;
	}
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;
#define ll long long
ll x; ll y; ll a; ll b;

int main(){
	ll cas;
	scanf("%lld",&cas);
	while(cas--){
		scanf("%lld %lld %lld %lld",&x,&y,&a,&b);
		if((y-x)%(a+b)) printf("-1\n");
		else	 	    printf("%lld\n",(y-x)/(a+b));
	}
	return 0;
}


#include <iostream>
using namespace std;
int t,i,x,y,a,b;
int main()
{
    cin>>t;
    for(i=0;i<t;i++)
    {
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0)cout<<(y-x)/(a+b)<<endl;
        else cout<<-1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int x,a,y,b,c;
int main(){
	scanf("%d%d%d%d",&x,&y,&a,&b);
	c=(y-x)%(a+b);
	if(c==0)
	printf("%d",(y-x)/(a+b));
	else
	printf("-1");
	return 0;
}


#include <stdio.h>
int main() {
	int t, x, y, a, b;
	scanf("%d", &t);
	while (t--) {
		scanf("%d%d%d%d", &x, &y, &a, &b);
		if ((y - x) % (a + b) == 0)
			printf("%d\n", (y - x) / (a + b));
		else
			printf("-1\n");
	}
	return 0;
}


#include<iostream>
using namespace std;
int main(){
    int q,a,b,c,d;
    cin>>q;
    while(q--){
        cin>>a>>b>>c>>d;
        if((b-a)%(c+d)==0) cout<<(b-a)/(c+d)<<endl;
        else cout<<-1<<endl;
    }
}


#include<iostream>
using namespace std;
int main()
{
	int n,x,y,a,b;
	cin >> n ;
	for(int i=1;i<=n;i++)
	{
		cin >> x >> y >> a >> b ;
		if((y-x)%(a+b)==0)
		{
			cout << (y-x)/(a+b) << endl ;
		}else
		{
			cout << -1 << endl ;
		}
	}
    return 0;
}


#include<cstdio>
using namespace std;
template<class T>inline void read(T&a){
	char c=getchar();int f=1;a=0;
	while(c>'9'||c<'0'){if(c=='-') f=-1;c=getchar();}
	while(c<='9'&&c>='0') a=(a<<1)+(a<<3)+c-48,c=getchar();
	a*=f;
}
template<class T>void write(T a){
	if(a<0) putchar('-'),a=-a;
	if(a>9) write(a/10);
	putchar(a%10+48);
}
int t,x,y,a,b;
int main(){
	read(t);while(t--) read(x),read(y),read(a),read(b),write((y-x)%(a+b)?-1:(y-x)/(a+b)),putchar('\n');
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int T;
int x,y,a,b;
int main()
{
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d%d",&x,&y,&a,&b);
		int t1=y-x,t2=a+b;
		if (t1%t2==0)
			printf("%d\n",t1/t2);
		else
			printf("-1\n");
	}
	return 0;
}


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

int t;
int x,y,a,b;
int main(){
    cin>>t;
    while(t--){
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0)cout<<(y-x)/(a+b)<<endl;
        else cout<<"-1"<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int x,y,a,b;
    cin>>x>>y>>a>>b;
    cout<<((y-x)%(a+b)==0 ? (y-x)/(a+b): -1)<<endl;
    return 0;
}


#include<iostream>
using namespace std;

int main()
{
    int x,y,a,b;
    cin>>x>>y>>a>>b;
    cout<<((y-x)%(a+b))==0? (y-x)/(a+b):-1;
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x,y,a,b;
        cin>>x>>y>>a>>b;
        cout<<((y-x)%(a+b)==0 ? (y-x)/(a+b): -1)<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;

int main()
{
    long long int t;
    cin>>t;
    while(t--)
    {
        long long int x,y,a,b,c=0;
        cin>>x>>y>>a>>b;
        while(x>=0 && y>=0 && x<y)
        {
            x=x+a;
            y=y-b;
            c++;
        }
        if(x==y)
        {
           cout<<c<<"\n";
        }
        else
        {
           cout<<-1<<"\n";
        }
    }
    return 0;
}


#include <iostream>
using namespace std;
int main()
{  int t;
 for(cin>>t;t;--t)
{ double x,y,a,b;
  cin>>x>>y>>a>>b;
  int count=0;bool yes=0;
  while(1)
  {   x=x+a;
      y=y-b;
    count++;
   if(x==y)
  {  yes=1;
    break;
  }
else if(x>y) break;

  }
 if(yes) cout<<count<<endl;
else cout<<"-1"<<endl;

}
return 0;
}


#include <iostream>
#define large_input ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
int main()
{  large_input
  int t;
 for(cin>>t;t;--t)
{ unsigned long long int x,y,a,b;
  cin>>x>>y>>a>>b;
  int count=0;bool yes=0;
  while(1)
  {   x=x+a;
      y=y-b;
    count++;
   if(x==y)
  {  yes=1;
    break;
  }
else if(x>y) break;

  }
 if(yes) cout<<count<<endl;
else cout<<"-1"<<endl;

}
return 0;
}


#include <iostream>
#define large_input ios_base::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
using namespace std;
int main()
{  large_input
  int t;
 for(cin>>t;t;--t)
{ ll x,y,a,b;
  cin>>x>>y>>a>>b;
  int count=0;bool yes=0;
  while(1)
  {   x=x+a;
      y=y-b;
    count++;
   if(x==y)
  {  yes=1;
    break;
  }
else if(x>y) break;

  }
 if(yes) cout<<count<<endl;
else cout<<"-1"<<endl;

}
return 0;
}


#include <iostream>
#define large_input ios_base::sync_with_stdio(false);cin.tie(NULL);

using namespace std;
int main()
{  large_input
  int t;
 for(cin>>t;t;--t)
{  int x,y,a,b;
  cin>>x>>y>>a>>b;
  cout << ((y - x) % (a + b) == 0 ? (y - x) / (a + b) : -1) << endl;
}
return 0;
}


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

main()
{
    ll x,y,a,b,t,s=1; cin>>t;
    cin>>x>>y>>a>>b;
    while(t--)
    {
    while(x<=y)
    {
        x=x+a;
        y=y-b;
        if(x==y){
            cout<<s<<endl;
            break;
        }
        else
            s++;
    }
    if(x!=y)
        cout<<-1<<endl;
    }
    return 0;
}


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

main()
{
    ll x,y,a,b,t,s=1;
    cin>>t;

    while(t--)
    {
        cin>>x>>y>>a>>b;
        s=1;
    while(x<=y)
    {
        x=x+a;
        y=y-b;
        if(x==y){
            cout<<s<<endl;
            break;
        }
        else
            s++;
    }
    if(x!=y)
        cout<<-1<<endl;
    }
    return 0;
}


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

void solve()
{
    ll x,y,a,b,s=1;
    cin>>x>>y>>a>>b;
    s=1;
    while(x<=y)
    {
        x=x+a;
        y=y-b;
        if(x==y){
            cout<<s<<endl;
            break;
        }
        else
            s++;
    }
    if(x!=y)
        cout<<-1<<endl;
    return ;
}
main()
{
    ll t;
    cin>>t;

    while(t--)
        solve();
}


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

main()
{
    ll x,y,a,b,t,s=1;
    cin>>t;

    while(t--)
    {
        cin>>x>>y>>a>>b;
        ll p=y-x;
        ll q=a+b;
        if(p%q==0)
            cout<<p/q<<endl;
        else
            cout<<-1<<endl;
    }
    return 0;
}


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

main()
{
    ll x,y,a,b,t,s=1;
    cin>>t;

    while(t--)
    {
        cin>>x>>y>>a>>b;
        s=1;
        x=x+a;
        y=y-b;
        while(x<=y)
            {
                if(x==y){
                cout<<s<<endl;
                break;
            }
            s++;
            x=x+a;
            y=y-b;
            if(x==y){
                cout<<s<<endl;
                break;
            }
            else
                s++;
            }
        if(x!=y)
            cout<<-1<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int x,y,a,b,c=0;
        cin>>x>>y>>a>>b;
        while(1)
        {
            x=x+a;
            y=y-b;
            c++;
            if(x==y)
            {
                cout<<c<<endl;
                break;
            }
            if(x>y)
            {
                cout<<"-1"<<endl;
                break;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int x,y,a,b,c=0;
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0)
        {
            cout<<(y-x)/(a+b)<<endl;
        }
        else
        {
            cout<<"-1"<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int x,y,a,b,c=0;
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0)
        {
            while(1)
            {
                x=x+a;
                y=y-b;
                c++;
                if(x==y)
                {
                    cout<<c<<endl;
                    break;
                }
            }
        }
        else
        {
            cout<<"-1"<<endl;
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    for(int i=1;i<=t;i++)
    {
        int x,y,a,b,c=0;
        cin>>x>>y>>a>>b;
        while(1)
        {
            if((y-x)%(a+b)==0)
            {
                x=x+a;
                y=y-b;
                c++;
                if(x==y)
                {
                    cout<<c<<endl;
                    break;
                }
            }
            else
            {
                cout<<"-1"<<endl;
                break;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
re int x = 0, f = 1; re char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n ;
signed main() {
int T = read();
while( T-- ) {
int x = read(), y = read(), a = read(), b = read() ;
if( (( y - x ) / ( a + b ) ) * ( a + b ) != ( y - x ) ) printf("-2\n") ;
else printf("%d\n", (( y - x ) / ( a + b ) ));
}
return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n ;
signed main() {
	int T = read();
	while( T-- ) {
		int x = read(), y = read(), a = read(), b = read() ;
		if( (( y - x ) / ( a + b ) ) * ( a + b ) != ( y - x ) ) printf("-1\n") ;
		else printf("%d\n", (( y - x ) / ( a + b ) ));
	}
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n ;
signed main() {
	int T = read();
	while( T-- ) {
		int x = read(), y = read(), a = read(), b = read() ;
		if( (( y - x ) / ( a + b ) ) * ( a + b ) != ( y - x ) ) printf("-2\n") ;
		else printf("%d\n", (( y - x ) / ( a + b ) ));
	}
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n ;
signed main() {
	int T = read();
	while( T-- ) {
		int x = read(), y = read(), a = read(), b = read() ,pp = 3;
		if( (( y - x ) / ( a + b ) ) * ( a + b ) != ( y - x ) ) printf("-2\n") ;
		else printf("%d\n", (( y - x ) / ( a + b ) ));
	}
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n ;
signed main() {
	int T = read();
	while( T-- ) {
		int x = read(), y = read(), a = read(), b = read() , pp = 1;
		if( (( y - x ) / ( a + b ) ) * ( a + b ) != ( y - x ) ) printf("-2\n") ;
		else printf("%d\n", (( y - x ) / ( a + b ) ));
	}
	return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
re int x = 0, f = 1; re char c = getchar();
while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
return x * f;
}
#define rep(i , a , b) for(int i = (a) , i##Limit = (b) ; i <= i##Limit ; ++ i)
#define drep(i , b , a) for(int i = (a) , i##Limit = (b) ; i >= i##Limit ; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 100005
il int Mul(int a, int b) { return 1ll * a * b % mod; }
il int Inc(int a, int b) { return (a += b) >= mod ? a - mod : a; }
il int Dec(int a, int b) { return (a -= b) < 0 ? a + mod : a; }
il int qpow(int a, int b) { int r = 1; while(b) { if(b & 1) r = Mul(r, a); a = Mul(a, a), b >>= 1; } return r; }
int n ;
signed main() {
int T = read();
while( T-- ) {
int x = read(), y = read(), a = read(), b = read() , pp = 0;
if( (( y - x ) / ( a + b ) ) * ( a + b ) != ( y - x ) ) printf("-2\n") ;
else printf("%d\n", (( y - x ) / ( a + b ) ));
}
return 0 ;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long x,y,a,b,i;
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0)
            cout<<(y-x)/(a+b)<<endl;
        else
            cout<<-1<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long x,y,a,b,cnt=0,i;
        cin>>x>>y>>a>>b;
        for(i=1;; i++)
        {
            if(a*i+b*i==y-x)
            {
                cout<<i<<endl;
                break;
            }
            else if(a*i+b*i>y-x)
            {
                cout<<-1<<endl;
                break;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        long long x,y,a,b,cnt=0;
        cin>>x>>y>>a>>b;
        while(x<y)
        {
            x+=a;
            y-=b;
            cnt++;
            if(x==y)
            {
                cout<<cnt<<endl;
                break;
            }
            else if(x>y)
            {
                cout<<"-1"<<endl;
                break;
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int x,y,a,b,cnt=0;
        cin>>x>>y>>a>>b;
        while(x<y)
        {
            x+=a;
            y-=b;
            cnt++;
            if(x==y)
            {
                cout<<cnt<<endl;
                break;
            }
            else if(x>y)
            {
                cout<<"-1"<<endl;
                break;
            }
        }
    }
}


include<iostream>
 using namesppace std;
 int main(){
  int n,x,y,a,b;
    cin>>n;
    while(n--){
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0){
            cout<<(y-x)/(a+b)<<endl;
        }
        else {
        cout<<-1<<endl;
    }
    return 0;
 }


 include<iostream>
 using namesppace std;
 int main(){
  int n,x,y,a,b;
    cin>>n;
    while(n--){
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0){
            cout<<(y-x)/(a+b)<<endl;
        }
        else
        cout<<-1<<endl;
    }
    return 0;
 }


#include<iostream>
using namespace std;
int main() {
	int n, x, y, a, b;
	cin >> n;
	while (n--) {
		cin >> x >> y >> a >> b;
		if ((y - x) % (a + b) == 0)
			cout << (y - x) / (a + b) << endl;

		else
			cout << -1 << endl;
	}
	return 0;
}


include<iostream>
 using namesppace std;
 int main(){
  int n,x,y,a,b;
    cin>>n;
    while(n--){
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0)
            cout<<(y-x)/(a+b)<<endl;

        else
        cout<<-1<<endl;
    }
    return 0;
 }


#include<iostream>
using namespace std;
int main(){
    int t,a,b,x,y;
    cin>>t;
    for(int i=1; i<=t; i++){
    cin>>a>>b>>x>>y;
    if((b-a)%(x+y)==0){
        cout<<(b-a)%(x+y);
    }else{
        cout<<-1;
    }
    }
}


#include<iostream>
using namespace std;
int main(){
    int t,a,b,x,y;
    cin>>t;
    for(int i=1; i<=t; i++){
    cin>>a>>b>>x>>y;
    if((b-a)%(x+y)==0){
        cout<<(b-a)/(x+y);
    }else{
        cout<<-1;
    }
    }
}


#include<iostream>
using namespace std;
int main(){
    int t,a,b,x,y;
    cin>>t;
    for(int i=1; i<=t; i++){
    cin>>a>>b>>x>>y;
    if((b-a)%(x+y)==0){
        cout<<(b-a)/(x+y)<<endl;
    }else{
        cout<<-1<<endl;
    }
    }
}


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

int main()
{
	int tc;
	cin >> tc;
	while (tc--)
	{
		int x, y, a, b;
		cin >> x >> y >> a >> b;
		cout << ((y - x) % (a + b) == 0 ? (y - x) / (a + b) : -1) << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t)
    {
        int x,y,b,a;
        cin>>x>>y>>a>>b;
        int count=0;
        while(x<y && x!=y)
        {
            x+=a;
            y-=b;
            count++;
        }
        if(x>y)
        {
            cout<<-1<<"\n";
        }
        else
        {cout<<count<<"\n";}
        t--;
    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t)
    {
        int x,y,b,a;
        cin>>x>>y>>a>>b;
        int count=0;
        while(x<y && x!=y)
        {
            x+=a;
            y-=b;
            count++;
        }
        if(x>y)
        {
            cout<<-1<<"\n";
        }
        cout<<count<<"\n";
        t--;
    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t)
    {
        int x,y,b,a;
        cin>>x>>y>>a>>b;
        if((y-x)%(a+b)==0)
        {
            cout<<(y-x)/(a+b)<<"\n";
        }
        else
        {cout<<-1<<"\n";}
        t--;
    }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t)
    {
        int x,y,b,a;
        cin>>x>>y>>a>>b;
        int count=0;
        while(x<y && x!=y)
        {
            x+=a;
            y-=b;
            count++;
        }
        cout<<count<<"\n";
        t--;
    }

}


#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<string>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<math.h>
#include<string.h>
#include<iostream>
#define ll long long

using namespace std;
int n;
ll a[101000];
ll no[101000];
ll from[101000];
ll nor[101000];
ll fromr[101000];
int main(){
    scanf("%d",&n);
    for(int i=0;i<n-1;i++){
        cin >> a[i];
    }
    from[0]=0;
    no[0]=0;
    ll ans=0;
    nor[n-1]=0;
    fromr[n-1]=0;
    for(int i=n-2;i>=0;i--){
        int odd=a[i]%2;
        nor[i]=max(nor[i+1]+a[i] -(odd+1)%2, a[i]>=2?fromr[i+1]+a[i]-odd:0);
        fromr[i]=a[i]>=2?fromr[i+1]+a[i]-odd:0;
    }
    for(int i=1;i<=n-1;i++){
        int odd=a[i-1]%2;
        no[i]=max(
            no[i-1]+ a[i-1] -  (odd+1)%2
        ,
            a[i-1]>=2?from[i-1]+ a[i-1]-  odd:0
        );
        from[i]=a[i-1]>=2?from[i-1]+a[i-1]- odd:0;
    }
    for(int i=0;i<n;i++){
        ans=max(ans,from[i]+nor[i]);
    }
    for(int i=0;i<n;i++){
        ans=max(ans,no[i]+fromr[i]);
    }

    //cout<<endl;
    cout <<ans <<endl;
}


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

const int N = 200000 + 10;
int n, s, a[N];
int memo[N][2][3][3];

int solve(int pos, int deg, int numodd, int state) {
    if (pos == n) {
        if (state == 2) return 0;
        return 1e18 + 7;
    }
    if (memo[pos][deg][numodd][state] != -1) return memo[pos][deg][numodd][state];
    int cur = 1e18 + 7;
    if (numodd + deg <= 2) {
        cur = min(cur, solve(pos + 1, 0, numodd + deg, state + (state == 1)) + a[pos + 1]);
    }
    if (state != 2 && a[pos + 1] > 0 && numodd + (deg + a[pos + 1]) % 2 <= 2) {
        cur = min(cur, solve(pos + 1, a[pos + 1] % 2, numodd + (deg + a[pos + 1]) % 2, 1));
    }
    if (state != 2 && a[pos + 1] > 1 && numodd + (deg + a[pos + 1] - 1) % 2 <= 2) {
        cur = min(cur, solve(pos + 1, (a[pos + 1] - 1) % 2, numodd + (deg + a[pos + 1] - 1) % 2, 1) + 1);
    }
    return memo[pos][deg][numodd][state] = cur;
}

main() {
    //freopen("inp.inp", "r", stdin);
    //freopen("out.out", "w", stdout);
    ios :: sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 1; i < n; ++i) {
        cin >> a[i];
        s += a[i];
    }
    memset(memo, -1, sizeof memo);
    cout << s - solve(0, 0, 0, 0);
}


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

#define fi(i,a,b)   for(long long i=a;i<=b;i++)
#define fr(i,a)     for(long long i=0;i<a;i++)
#define fd(i,a,b)   for(long long i=b;i>=a;i--)
#define clr(x)      memset(x,0,sizeof(x))
#define cln(x)      memset(x,-1,sizeof(x))
#define __          printf(" ")
#define _           printf("\n")
#define _o          printf("1\n")
#define stree       long long lft=node<<1,rht=(node<<1)|1,mid=(s+e)>>1
#define mod         1000000007
#define read()      freopen("in.txt","r",stdin);

long long a[100100];
long long lft[100010][2],rht[100010][2];

main(){
    long long n,ans=0;
    scanf("%lld",&n);n--;
    fi(i,1,n) scanf("%lld",a+i);n++;

    fi(i,2,n) {
        lft[i][0]=max(lft[i-1][1],lft[i-1][0])+(a[i-1]%2?a[i-1]:a[i-1]-1);
        if(a[i-1]!=1) lft[i][1]=lft[i-1][1]+(a[i-1]%2?a[i-1]-1:a[i-1]);
    }

    fd(i,1,n-1){
        rht[i][0]=max(rht[i+1][1],rht[i+1][0])+(a[i]%2?a[i]:a[i]-1);
        if(a[i]!=1) rht[i][1]=rht[i+1][1]+(a[i]%2?a[i]-1:a[i]);
    }

    fi(i,1,n) ans=max(ans,max(lft[i][1]+max(rht[i][0],rht[i][1]),rht[i][1]+max(lft[i][0],lft[i][1])));
    printf("%lld\n",ans);
    return 0;
}


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

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mod 1000000007ll
#define LL long long

using namespace std;

LL a[100005], b[100005];
LL la[100005], ra[100006];
LL lb[100005], rb[100006];

void sol(int n, LL *c, LL *a, LL *b) {
    int i;

    a[0] = c[0] - c[0] % 2;
    b[0] = c[0] - (c[0] + 1) % 2;

    for (i = 1; i < n; i++){
    if (c[i] > 1)
        a[i] = a[i - 1] + c[i] - c[i] % 2;
    b[i] = b[i - 1] + c[i] - (c[i] + 1) % 2;
    b[i] = max(a[i - 1] + c[i] - (c[i] + 1) % 2, b[i]);
    }

    /*for (i = 0; i < n; i++)
    cout << a[i] << " ";
    cout << endl;
    for (i = 0; i < n; i++)
    cout << b[i] << " ";*/
    for (i = 0; i < n; i++)
    a[i] = max(a[i], b[i]);
/*    cout << endl;
cout << endl;*/
}
LL ans;

int main() {
    int i, n;

    cin >> n;
    for(i = 0; i < n - 1; i++)
    cin >> a[i];

    n--;
    sol(n, a, la, lb);
    for (i = 0; i < n; i++)
    b[i] = a[n - i - 1];
    sol(n, b, ra, rb);

    ans = max(la[n - 1], ra[n - 1]);
    for (i = 0; i < n - 2; i++)
    ans = max(ans, la[i] + ra[n - 2 - i]);

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


using namespace std;
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORE(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
const int MAXN = 2*1e5;
const int INF  = 1e9 + 7;

int n, a[MAXN], L[MAXN], R[MAXN], odd[MAXN], Left[MAXN], Right[MAXN];
long long mmax[MAXN],  SumOdd[MAXN];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    //freopen("202E.inp", "r", stdin);
    //freopen("202E.out", "w", stdout);

    cin >> n;
    FORE(i, 1, n - 1) cin >> a[i];
    L[1] = 1;
    FORE(i, 2, n - 1) {
        L[i] = i;
        while (L[i] > 1 && a[ L[i] - 1] >= a[i]) L[i] = L[L[i] - 1];
    }
    Left[1] = 0;
    FORE(i, 2, n) {
        int tmp = a[i - 1];
        if (tmp % 2 == 1) tmp--;
        Left[i] = tmp * (i - 1 - L[i - 1] + 1);
    }

    R[n - 1] = n - 1;
    FORD(i, n - 2, 1) {
        R[i] = i;
        while (R[i] < n - 1 && a[ R[i] + 1] >= a[i]) R[i] = R[R[i] + 1];
    }
    Right[n] = 0;
    FORD(i, n - 1, 1) {
        int tmp = a[i];
        if (tmp % 2 == 1) tmp--;
        Right[i] = tmp * (R[i] - i + 1);
    }
    //FORE(i, 1, n) cout<<Right[i]<<" ";cout<<endl;

    FORE(i, 2, n) {
        odd[i - 1] = a[i - 1];
        if (odd[i - 1] % 2 == 0) odd[i - 1]--;
        SumOdd[i] = SumOdd[i - 1] + odd[i - 1];
    }
    //cout<<SumOdd[n]<<endl;
    mmax[n] = Right[n] + SumOdd[n];
    FORD(i, n - 1, 1) mmax[i] = max(mmax[i + 1], Right[i] + SumOdd[i]);
    long long ans = 0;
    FORE(i, 1, n - 1) ans = max(ans, Left[i] - SumOdd[i] + mmax[i]);

    //FORE(i, 1, n) cout<<Left[i]<<" ";cout<<endl;
    //FORE(i, 1, n) cout<<Right[i]<<" ";cout<<endl;
    //FORE(i, 1, n) cout<<SumOdd[i]<<" ";cout<<endl;
    cout<<ans;
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORE(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
const int MAXN = 2*1e5;
const int INF  = 1e9 + 7;

int n, a[MAXN], L[MAXN], R[MAXN], odd[MAXN], Left[MAXN], Right[MAXN];
long long mmax[MAXN],  SumOdd[MAXN];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    //freopen("202E.inp", "r", stdin);
    //freopen("202E.out", "w", stdout);

    cin >> n;
    FORE(i, 1, n - 1) cin >> a[i];
    Left[1] = 0;
    FORE(i, 2, n) {
        int x = a[i - 1];
        if (x % 2 == 1) x--;
        if (!x) Left[i] = 0;
        else {
            Left[i] = Left[i - 1] + x;
        }
    }

    Right[n] = 0;
    FORD(i, n - 1, 1){
        int x = a[i];
        if (x % 2 == 1) x--;
        if (!x) Right[i] = 0;
        else {
            Right[i] = Right[i + 1] + x;
        }
    }

    FORE(i, 2, n) {
        odd[i - 1] = a[i - 1];
        if (odd[i - 1] % 2 == 0) odd[i - 1]--;
        SumOdd[i] = SumOdd[i - 1] + odd[i - 1];
    }
    //cout<<SumOdd[n]<<endl;
    mmax[n] = Right[n] + SumOdd[n];
    FORD(i, n - 1, 1) mmax[i] = max(mmax[i + 1], Right[i] + SumOdd[i]);
    long long ans = 0;
    //FORE(i, 1, n) {
    //    ans = max(ans, Left[i] - SumOdd[i] + mmax[i]);
    //    cout<<i<<" "<<ans<<"wtf"<<endl;
    //}

    //FORE(i, 1, n) cout<<Left[i]<<" ";cout<<endl;
    //FORE(i, 1, n) cout<<Right[i]<<" ";cout<<endl;
    //FORE(i, 1, n) cout<<SumOdd[i]<<" ";cout<<endl;
    cout<<ans;
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORE(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
const int MAXN = 2*1e5;
const int INF  = 1e9 + 7;

long long  n, a[MAXN], L[MAXN], R[MAXN], odd[MAXN], Left[MAXN], Right[MAXN];
long long mmax[MAXN],  SumOdd[MAXN];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    //freopen("202E.inp", "r", stdin);
    //freopen("202E.out", "w", stdout);

    cin >> n;
    FORE(i, 1, n - 1) cin >> a[i];
    Left[1] = 0;
    FORE(i, 2, n) {
        int x = a[i - 1];
        if (x % 2 == 1) x--;
        if (!x) Left[i] = 0;
        else {
            Left[i] = Left[i - 1] + x;
        }
    }

    Right[n] = 0;
    FORD(i, n - 1, 1){
        int x = a[i];
        if (x % 2 == 1) x--;
        if (!x) Right[i] = 0;
        else {
            Right[i] = Right[i + 1] + x;
        }
    }

    FORE(i, 2, n) {
        odd[i - 1] = a[i - 1];
        if (odd[i - 1] % 2 == 0) odd[i - 1]--;
        SumOdd[i] = SumOdd[i - 1] + odd[i - 1];
    }
    //cout<<SumOdd[n]<<endl;
    mmax[n] = Right[n] + SumOdd[n];
    FORD(i, n - 1, 1) mmax[i] = max(mmax[i + 1], Right[i] + SumOdd[i]);
    long long ans = 0;
    FORE(i, 1, n) {
        ans = max(ans, Left[i] - SumOdd[i] + mmax[i]);
    //    cout<<i<<" "<<ans<<"wtf"<<endl;
    }

    //FORE(i, 1, n) cout<<Left[i]<<" ";cout<<endl;
    //FORE(i, 1, n) cout<<Right[i]<<" ";cout<<endl;
    //FORE(i, 1, n) cout<<SumOdd[i]<<" ";cout<<endl;
    cout<<ans;
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORE(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
const int MAXN = 2*1e5;
const int INF  = 1e9 + 7;

int n, a[MAXN], L[MAXN], R[MAXN], odd[MAXN], Left[MAXN], Right[MAXN];
long long mmax[MAXN],  SumOdd[MAXN];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    freopen("202E.inp", "r", stdin);
    freopen("202E.out", "w", stdout);

    cin >> n;
    FORE(i, 1, n - 1) cin >> a[i];
    L[1] = 1;
    FORE(i, 2, n - 1) {
        L[i] = i;
        while (L[i] > 1 && a[ L[i] - 1] >= a[i]) L[i] = L[L[i] - 1];
    }
    Left[1] = 0;
    FORE(i, 2, n) {
        int tmp = a[i - 1];
        if (tmp % 2 == 1) tmp--;
        Left[i] = tmp * (i - 1 - L[i - 1] + 1);
    }

    R[n - 1] = n - 1;
    FORD(i, n - 2, 1) {
        R[i] = i;
        while (R[i] < n - 1 && a[ R[i] + 1] >= a[i]) R[i] = R[R[i] + 1];
    }
    Right[n] = 0;
    FORD(i, n - 1, 1) {
        int tmp = a[i];
        if (tmp % 2 == 1) tmp--;
        Right[i] = tmp * (R[i] - i + 1);
    }
    //FORE(i, 1, n) cout<<Right[i]<<" ";cout<<endl;

    FORE(i, 2, n) {
        odd[i - 1] = a[i - 1];
        if (odd[i - 1] % 2 == 0) odd[i - 1]--;
        SumOdd[i] = SumOdd[i - 1] + odd[i - 1];
    }
    //cout<<SumOdd[n]<<endl;
    mmax[n] = Right[n] + SumOdd[n];
    FORD(i, n - 1, 1) mmax[i] = max(mmax[i + 1], Right[i] + SumOdd[i]);
    long long ans = 0;
    FORE(i, 1, n - 1) ans = max(ans, Left[i] - SumOdd[i] + mmax[i + 1]);
    cout<<ans;
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORE(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
const int MAXN = 2*1e5;
const int INF  = 1e9 + 7;

int n, a[MAXN], L[MAXN], R[MAXN], odd[MAXN], Left[MAXN], Right[MAXN];
long long mmax[MAXN],  SumOdd[MAXN];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    //freopen("202E.inp", "r", stdin);
    //freopen("202E.out", "w", stdout);

    cin >> n;
    FORE(i, 1, n - 1) cin >> a[i];
    L[1] = 1;
    FORE(i, 2, n - 1) {
        L[i] = i;
        while (L[i] > 1 && a[ L[i] - 1] >= a[i]) L[i] = L[L[i] - 1];
    }
    Left[1] = 0;
    FORE(i, 2, n) {
        int tmp = a[i - 1];
        if (tmp % 2 == 1) tmp--;
        Left[i] = tmp * (i - 1 - L[i - 1] + 1);
    }

    R[n - 1] = n - 1;
    FORD(i, n - 2, 1) {
        R[i] = i;
        while (R[i] < n - 1 && a[ R[i] + 1] >= a[i]) R[i] = R[R[i] + 1];
    }
    Right[n] = 0;
    FORD(i, n - 1, 1) {
        int tmp = a[i];
        if (tmp % 2 == 1) tmp--;
        Right[i] = tmp * (R[i] - i + 1);
    }
    //FORE(i, 1, n) cout<<Right[i]<<" ";cout<<endl;

    FORE(i, 2, n) {
        odd[i - 1] = a[i - 1];
        if (odd[i - 1] % 2 == 0) odd[i - 1]--;
        SumOdd[i] = SumOdd[i - 1] + odd[i - 1];
    }
    //cout<<SumOdd[n]<<endl;
    mmax[n] = Right[n] + SumOdd[n];
    FORD(i, n - 1, 1) mmax[i] = max(mmax[i + 1], Right[i] + SumOdd[i]);
    long long ans = 0;
    FORE(i, 1, n - 1) ans = max(ans, Left[i] - SumOdd[i] + mmax[i + 1]);
    cout<<ans;
    return 0;
}


using namespace std;
#include<bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORE(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = a; i >= b; i--)
const int MAXN = 2*1e5;
const int INF  = 1e9 + 7;

int n, a[MAXN], L[MAXN], R[MAXN], odd[MAXN], Left[MAXN], Right[MAXN];
long long mmax[MAXN],  SumOdd[MAXN];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);

    //freopen("202E.inp", "r", stdin);
    //freopen("202E.out", "w", stdout);

    cin >> n;
    FORE(i, 1, n - 1) cin >> a[i];
    Left[1] = 0;
    FORE(i, 2, n) {
        int x = a[i - 1];
        if (x % 2 == 1) x--;
        if (!x) Left[i] = 0;
        else {
            Left[i] = Left[i - 1] + x;
        }
    }

    Right[n] = 0;
    FORD(i, n - 1, 1){
        int x = a[i];
        if (x % 2 == 1) x--;
        if (!x) Right[i] = 0;
        else {
            Right[i] = Right[i + 1] + x;
        }
    }

    FORE(i, 2, n) {
        odd[i - 1] = a[i - 1];
        if (odd[i - 1] % 2 == 0) odd[i - 1]--;
        SumOdd[i] = SumOdd[i - 1] + odd[i - 1];
    }
    //cout<<SumOdd[n]<<endl;
    mmax[n] = Right[n] + SumOdd[n];
    FORD(i, n - 1, 1) mmax[i] = max(mmax[i + 1], Right[i] + SumOdd[i]);
    long long ans = 0;
    FORE(i, 1, n) {
        ans = max(ans, Left[i] - SumOdd[i] + mmax[i]);
    //    cout<<i<<" "<<ans<<"wtf"<<endl;
    }

    //FORE(i, 1, n) cout<<Left[i]<<" ";cout<<endl;
    //FORE(i, 1, n) cout<<Right[i]<<" ";cout<<endl;
    //FORE(i, 1, n) cout<<SumOdd[i]<<" ";cout<<endl;
    cout<<ans;
    return 0;
}