#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define MOD 1000000007
void adde(  vector<ll> adj[],ll u,ll v)
{
  adj[u].pb(v);
  adj[v].pb(u);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t;
  cin>>t;
  while(t--)
  {
    ll a,b,q;
    cin>>a>>b>>q;
    ll size=a*b/__gcd(a,b);
    ll dp[size];
    ll tot=0;
    for(ll i=1;i<size;i++)
    {
      if((((i)%a)%b)!=(((i)%b)%a))
      {
        dp[i]=1;
        tot++;
      }
      else
      dp[i]=0;
    }
    if((((size)%a)%b)!=(((size)%b)%a))
    {dp[0]=1;
    tot++;}
    else
    dp[0]=0;
    while(q--)
    {
      ll l,r;
      cin>>l>>r;
      ll ans=0;
      if((l-r+1)<=2*size)
      {
        for(ll i=l;i<=r;i++)
        {
          ans+=dp[i%size];
        }
      }
      else
      {
        ll temp=l/size;
        if(l%size!=0)
        temp++;
        temp*=size;
        for(ll i=temp-1;i>=l;i--)
        ans+=dp[i%size];
        ll temp1=r/size;
        if(r%size!=0)
        temp1--;
        temp1*=size;
        for(ll i=temp1;i<=r;i++)
        ans+=dp[i%size];
        ll te=(temp1-temp)/size;
        ans+=te*tot;
      }
      cout<<ans<<" ";
    }
    cout<<"\n";
  }
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define mk make_pair
#define MOD 1000000007
void adde(  vector<ll> adj[],ll u,ll v)
{
  adj[u].pb(v);
  adj[v].pb(u);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll t;
  cin>>t;
  while(t--)
  {
    ll a,b,q;
    cin>>a>>b>>q;
    ll size=a*b/(__gcd(a,b));
    //cout<<size<<"\n";
    ll dp[size+1];
    ll tot=0;
    for(ll i=1;i<=size;i++)
    {
      if((i%a)%b!=(i%b)%a)
      {
        dp[i]=1;
        tot++;
      }
      else
      dp[i]=0;
    }
    for(ll i=2;i<=size;i++)
    {
      dp[i]+=dp[i-1];
    }
    // for(ll i=1;i<=size;i++)
    // {
    //   cout<<dp[i]<<" ";
    // }
    // cout<<"\n";
    dp[0]=0;
    while(q--)
    {
      ll l,r;
      cin>>l>>r;
      ll pnt=l/size;
      // if(l%size==0)
      // {
      //   pnt=size*(pnt);
      // }
      // else
      pnt=size*(pnt+1);
      ll ans=0;
      ll te=size;
      ll flag=0;
      ll temp1=pnt;

        if(pnt<=r)
        {

        }
        else
        flag=1;
        pnt=min(pnt,r);
        ll yuhi=pnt-l;
        if(flag==0)
        ans+=dp[size]-dp[size-yuhi];
        if(flag==1)
        {
          // ll temp3,temp4;
          // if(r%size==0)
          // temp3=size;
          // else
          // temp3=(r%size);
          // if(l%size==0)
          // temp4=size;
          // else
          // temp4=(l%size);

          temp1-=size;
          if(l%size==0)
          temp1-=size;
          ans+=dp[r-temp1]-dp[l-temp1-1];
          cout<<abs(ans)<<" ";
        }
        else
        {
          pnt=r/size;
          pnt=pnt*size;
          ll temp2=pnt;
          yuhi=r-pnt;
          //yuhi--;
          if(yuhi>=0)
          ans+=dp[1+yuhi]-dp[1];
          // while(pnt<=r)
          // {
          //
          //     ans+=dp[te];
          //   pnt++;
          //   te++;
          // }
          ans+=((temp2-temp1)/size)*tot;
          cout<<abs(ans)<<" ";
        }

    }
    cout<<"\n";
  }
  return 0;
}


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

int gcd(int a, int b){
     if(a == 0) return b;
     return gcd(b % a, a);
}

main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int T; cin >> T;
     while(T--){
          int a, b, Q;
          cin >> a >> b >> Q;
          int lcm = a*b/gcd(a,b);
          while(Q--){
               int l, r; cin >> l >> r;
               l = max({l, a, b});
               if(l > r){
                    cout << 0 << " ";
                    continue;
               }
               if(r < lcm){
                    cout << r-l+1 << " ";
                    continue;
               }
               int quanti = r/lcm - (l-1)/lcm;
               int ans = r-l+1;
               ans -= max(a, b)*(quanti-1);
               int n = (r/lcm)*lcm;
               for(int i = 0; i < max(a, b); i++, n++){
                    if(n > r) break;
                    ans--;
               }
               cout << ans << " ";
          }
          cout << "\n";
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int gcd(int a, int b){
    if(!b) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b){
    return a / gcd(a, b) * b;
}

void solve(){
    ll a, b, Q;
    cin >> a >> b >> Q;
    if(a > b) swap(a, b);
    while(Q--){
        ll l, r; cin >> l >> r;
        ll ans = (r-l+1);
        ll d = lcm(a, b);
        ll dl = (l + d - 1) / d;
        ll dr = r / d;
        if(dl <= dr){
            ans -= (dr - dl) * b;
            ans -= min(r, dr*d+b-1) - dr*d + 1;
        }
        if(((l%a)%b) == ((l%b)%a) && l < dl*d){
            ll dl2 = min(l / d * d + b - 1, r);
            ans -= (dl2-l+1);
        }
        cout << ans << " \n"[Q == 0];
    }
}

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T; cin >> T;
    while(T--){
        solve();
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int gcd(int a, int b){
    if(!b) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b){
    return a / gcd(a, b) * b;
}

void solve(){
    ll a, b, Q;
    cin >> a >> b >> Q;
    if(a > b) swap(a, b);
    while(Q--){
        ll l, r; cin >> l >> r;
        ll ans = (r-l+1);
        ll d = lcm(a, b);
        ll dl = (l + d - 1) / d;
        ll dr = r / d;
        if(dl <= dr){
            ans -= (dr - dl) * b;
            ans -= min(r, dr*d+b-1) - dr*d + 1;
        }
        if(l % d){
            for(int i = l; i <= min(l+d, r); i++){
                if(((i%a)%b) == ((i%b)%a)) ans--;
                else break;
            }
        }
        cout << ans << " \n"[Q == 0];
    }
}

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T; cin >> T;
    while(T--){
        solve();
    }
}


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

int gcd(int a, int b){
     if(b == 0) return a;
     return gcd(b, a%b);
}

int b_search(int inf, int sup, int x, int lcm){
     while(sup - inf > 1){
          int mid = (inf + sup) >> 1;
          if(mid*lcm < x) inf = mid;
          else sup = mid;
     }
     return inf;
}

main(){
     ios_base::sync_with_stdio(false);
     cin.tie(nullptr);
     int T; cin >> T;
     while(T--){
          int a, b, q; cin >> a >> b >> q;
          if(a > b) swap(a, b);
          while(q--){
               int l, r; cin >> l >> r; l = max(l, b);
               if(l > r){cout << 0 << " "; continue;}
               int ans = r - l + 1;
               int lcm = a/gcd(a,b)*b;
               l = max(l, lcm);
               if(l > r){cout << ans << " "; continue;}
               int lowl = b_search(l/lcm-1, l/lcm+2, l, lcm);
               int upl = lowl+1;
               int lowr = b_search(r/lcm-1, r/lcm+2, r, lcm);
               ans -= max((long long) 0, b-(l-lowl*lcm));
               ans -= (lowr-upl+1)*(b);
               ans += max((long long) 0, lowr*lcm+b-r);
               cout << ans << " ";
          }
          cout << "\n";
     }
}


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

int gcd(int a, int b){
     if(b == 0) return a;
     return gcd(b, a%b);
}

int b_search(int inf, int sup, int x, int lcm){
     while(sup - inf > 1){
          int mid = (inf + sup) >> 1;
          if(mid*lcm < x) inf = mid;
          else sup = mid;
     }
     return inf;
}

main(){
     ios_base::sync_with_stdio(false);
     cin.tie(nullptr);
     int T; cin >> T;
     while(T--){
          int a, b, q; cin >> a >> b >> q;
          if(a > b) swap(a, b);
          while(q--){
               int l, r; cin >> l >> r; l = max(l, b);
               if(l > r){cout << 0 << " "; continue;}
               int ans = r - l + 1;
               int lcm = a/gcd(a,b)*b;
               l = max(l, lcm);
               if(l > r){cout << ans << " "; continue;}
               int lowl = b_search(l/lcm-1, l/lcm+2, l, lcm);
               int upl = lowl+1;
               int lowr = b_search(r/lcm-1, r/lcm+2, r, lcm);
               ans -= max((long long) 0, b-(l-lowl*lcm+1));
               ans -= (lowr-upl+1)*(b);
               ans += max((long long) 0, lowr*lcm+b-r-1);
               cout << ans << " ";
          }
          cout << "\n";
     }
}


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

int gcd(int a, int b){
     if(a == 0) return b;
     return gcd(b % a, a);
}

main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int T; cin >> T;
     while(T--){
          int a, b, Q;
          cin >> a >> b >> Q;
          int lcm = a*b/gcd(a,b);
          while(Q--){
               int l, r;
               cin >> l >> r;
               l = max({l, a, b});
               if(l > r){
                    cout << 0 << " ";
                    continue;
               }
               int quanti = r/lcm - (l-1)/lcm;
               int ans = r-l+1;
               ans -= max(a, b)*(quanti-1);
               int n = (r/lcm)*lcm;
               for(int i = 0; i < max(a, b); i++){
                    if(n > r) break;
                    ans--;
               }
               cout << ans << " ";
          }
          cout << "\n";
     }
}


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

int gcd(int a, int b){
     if(b == 0) return a;
     return gcd(b, a%b);
}

int b_search(int inf, int sup, int x, int lcm){
     while(sup - inf > 1){
          int mid = (inf + sup) >> 1;
          if(mid*lcm < x) inf = mid;
          else sup = mid;
     }
     return inf;
}

main(){
     ios_base::sync_with_stdio(false);
     cin.tie(nullptr);
     int T; cin >> T;
     while(T--){
          int a, b, q; cin >> a >> b >> q;
          if(a > b) swap(a, b);
          while(q--){
               int l, r; cin >> l >> r; l = max(l, b);
               if(l > r){cout << 0 << " "; continue;}
               int ans = r - l + 1;
               int lcm = a/gcd(a,b)*b;
               l = max(l, lcm);
               if(l > r){cout << ans << " "; continue;}
               int lowl = b_search(l/lcm-1, l/lcm+2, l, lcm);
               int upl = lowl+1;
               int lowr = b_search(r/lcm-1, r/lcm+2, r, lcm);
               ans -= max((long long) 0, b-(l-lowl*lcm));
               ans -= (lowr-upl+1)*(b);
               ans += max((long long) 0, lowr*lcm+b-r-1);
               cout << ans << " ";
          }
          cout << "\n";
     }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int gcd(int a, int b){
    if(!b) return a;
    return gcd(b, a % b);
}

int lcm(int a, int b){
    return a / gcd(a, b) * b;
}

void solve(){
    ll a, b, Q;
    cin >> a >> b >> Q;
    if(a > b) swap(a, b);
    while(Q--){
        ll l, r; cin >> l >> r;
        ll ans = (r-l+1);
        ll d = lcm(a, b);
        ll dl = (l + d - 1) / d;
        ll dr = r / d;
        if(dl <= dr){
            ans -= (dr - dl) * b;
            ans -= min(r, dr*d+b-1) - dr*d + 1;
        }
        for(int i = l; i <= min((l+d-1)/d*d-1, r); i++){
            if(((i%a)%b) == ((i%b)%a)) ans--;
            else break;
        }
        cout << ans << " \n"[Q == 0];
    }
}

main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int T; cin >> T;
    while(T--){
        solve();
    }
}


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

int gcd(int a, int b){
     if(a == 0) return b;
     return gcd(b % a, a);
}

main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int T; cin >> T;
     while(T--){
          int a, b, Q;
          cin >> a >> b >> Q;
          int lcm = a*b/gcd(a,b);
          while(Q--){
               int l, r; cin >> l >> r;
               l = max({l, a, b});
               if(l > r){
                    cout << 0 << " ";
                    continue;
               }
               int quanti = r/lcm - (l-1)/lcm;
               int ans = r-l+1;
               ans -= max(a, b)*(quanti-1);
               int n = (r/lcm)*lcm;
               for(int i = 0; i < max(a, b); i++){
                    if(n > r) break;
                    ans--;
               }
               cout << ans << " ";
          }
          cout << "\n";
     }
}


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

int gcd(int a, int b){
     if(a == 0) return b;
     return gcd(b % a, a);
}

main(){
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int T; cin >> T;
     while(T--){
          int a, b, Q;
          cin >> a >> b >> Q;
          int lcm = a*b/gcd(a,b);
          while(Q--){
               int l, r; cin >> l >> r;
               l = max({l, a, b});
               if(l > r){
                    cout << 0 << " ";
                    continue;
               }
               if(r < lcm){
                    cout << r-l+1 << " ";
                    continue;
               }
               int quanti = r/lcm - (l-1)/lcm;
               int ans = r-l+1;
               ans -= max(a, b)*(quanti-1);
               int n = (r/lcm)*lcm;
               for(int i = 0; i < max(a, b); i++){
                    if(n > r) break;
                    ans--;
               }
               cout << ans << " ";
          }
          cout << "\n";
     }
}


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

int gcd(int a, int b){
     if(b == 0) return a;
     return gcd(b, a%b);
}

int b_search(int inf, int sup, int x, int lcm){
     while(sup - inf > 1){
          int mid = (inf + sup) >> 1;
          if(mid*lcm < x) inf = mid;
          else sup = mid;
     }
     return inf;
}

main(){
     ios_base::sync_with_stdio(false);
     cin.tie(nullptr);
     int T; cin >> T;
     while(T--){
          int a, b, q; cin >> a >> b >> q;
          if(a > b) swap(a, b);
          while(q--){
               int l, r; cin >> l >> r; l = max(l, b);
               if(l > r){cout << 0 << " "; continue;}
               int ans = r - l + 1;
               int lcm = a/gcd(a,b)*b;
               l = max(l, lcm);
               if(l > r){cout << ans << " "; continue;}
               int lowl = b_search(l/lcm-1, l/lcm+2, l, lcm);
               int upl = lowl+1;
               int lowr = b_search(r/lcm-1, r/lcm+2, r, lcm);
               ans -= max((long long) 0, b-(l-lowl*lcm)+1);
               ans -= (lowr-upl+1)*(b);
               ans += max((long long) 0, lowr*lcm+b-r-1);
               cout << ans << " ";
          }
          cout << "\n";
     }
}


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,q,c;
		cin>>a>>b>>q;
		c=(a*b)/__gcd(a,b);
		while(q--)
		{
			ll l,r;
			cin>>l>>r;
			ll al,cnt=0,fake1,fake2;
			al=r/c-l/c;
			cnt=al*(max(a,b)-max(a,b)/min(a,b));

			if((r/c)*c+max(a,b)>r&&al>0)
			{
				fake1=(r/c)*c+max(a,b)-r;
				cnt-=fake1;
			}
			if((l/c)*c+max(a,b)>l&&al>0)
			{
				fake2=(l/c)*c+max(a,b)-l;
				cnt-=fake2;
			}
			ll ans;
			ans=(r-l)-cnt;
			if(al==0)
			{
				ll l1;
				l1=max(l,max(a,b));
				if(a!=b&&r==max(a,b))
				ans=1;
				else if(a!=b&&l==r&&l>max(a,b))
				ans=1;
				else if((l1>r))
				ans=0;
				else
				ans=(r-l1+1);
			}
			cout<<ans<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,q,c;
		cin>>a>>b>>q;
		c=(a*b)/__gcd(a,b);
		while(q--)
		{
			ll l,r;
			cin>>l>>r;
			ll al,cnt=0,fake1,fake2;
			al=r/c-l/c;
			cnt=al*(max(a,b)-max(a,b)/min(a,b));

			if((r/c)*c+max(a,b)>r&&al>0)
			{
				fake1=(r/c)*c+max(a,b)-r;
				cnt-=fake1;
			}
			if((l/c)*c+max(a,b)>l&&al>0)
			{
				fake2=(l/c)*c+max(a,b)-l;
				cnt-=fake2;
			}
			ll ans;
			ans=(r-l)-cnt;
			if(al==0)
			{
				ll l1;
				l1=max(l,max(a,b));
				if(a!=b&&r==max(a,b)&&l!=r)
				ans=1;
				else if((l1>=r))
				ans=0;
				else
				ans=(r-l1+1);
			}
			cout<<ans<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,q,c;
		cin>>a>>b>>q;
		c=(a*b)/__gcd(a,b);
		while(q--)
		{
			ll l,r;
			cin>>l>>r;
			ll al,cnt=0,fake1,fake2;
			al=r/c-l/c;
			cnt=al*(max(a,b)-max(a,b)/min(a,b));

			if((r/c)*c+max(a,b)>r&&al>0)
			{
				fake1=(r/c)*c+max(a,b)-r;
				cnt-=fake1;
			}
			if((l/c)*c+max(a,b)>l&&al>0)
			{
				fake2=(l/c)*c+max(a,b)-l;
				cnt-=fake2;
			}
			ll ans;
			ans=(r-l)-cnt;
			if(al==0)
			{
				ll l1;
				l1=max(l,max(a,b));
				if((l1>=r))
				ans=0;
				else
				ans=(r-l1+1);
			}
			cout<<ans<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,q,c;
		cin>>a>>b>>q;
		c=(a*b)/__gcd(a,b);
		while(q--)
		{
			ll l,r;
			cin>>l>>r;
			ll al,cnt=0,fake1,fake2;
			al=r/c-l/c;
			cnt=al*(max(a,b)-max(a,b)/min(a,b));

			if((r/c)*c+max(a,b)>r&&al>0)
			{
				ll k1;
				fake1=(r/c)*c+max(a,b)-r;
				k1=((r/c)*c+max(a,b))/min(a,b)-r/c;
				cnt-=fake1;
				cnt+=k1;
			}
			if((l/c)*c+max(a,b)>l&&al>0)
			{
				ll k1;
				fake2=(l/c)*c+max(a,b)-l;
				k1=((l/c)*c+max(a,b))/min(a,b)-l/c;
				cnt-=fake2;
				cnt+=k1;
			}
			ll ans;
			ans=(r-l)-cnt;
			if(al==0)
			{
				ll l1;
				l1=max(l,max(a,b));
				if(a!=b&&r==max(a,b))
				ans=1;
				else if(a!=b&&l==r&&l>max(a,b))
				ans=1;
				else if((l1>r))
				ans=0;
				else
				ans=(r-l1+1);
			}
			cout<<ans<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,q,c;
		cin>>a>>b>>q;
		c=(a*b)/__gcd(a,b);
		while(q--)
		{
			ll l,r;
			cin>>l>>r;
			ll al,cnt=0,fake1,fake2;
			al=r/c-l/c;
			cnt=al*(max(a,b)-max(a,b)/min(a,b));

			if((r/c)*c+max(a,b)>r&&al>0)
			{
				fake1=(r/c)*c+max(a,b)-r;
				cnt-=fake1;
			}
			if((l/c)*c+max(a,b)>l&&al>0)
			{
				fake2=(l/c)*c+max(a,b)-l;
				cnt-=fake2;
			}
			ll ans;
			ans=(r-l)-cnt;
			if(al==0)
			{
				ll l1;
				l1=max(l,max(a,b));
				if(a!=b&&r==max(a,b)||l==r)
				ans=1;
				else if((l1>r))
				ans=0;
				else
				ans=(r-l1+1);
			}
			cout<<ans<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,q,c;
		cin>>a>>b>>q;
		c=(a*b)/__gcd(a,b);
		while(q--)
		{
			ll l,r;
			cin>>l>>r;
			ll al,cnt=0,fake1,fake2;
			al=r/c-l/c;
			cnt=al*(max(a,b)-max(a,b)/min(a,b));

			if((r/c)*c+max(a,b)>r&&al>0)
			{
				ll k1;
				fake1=(r/c)*c+max(a,b)-r;
				k1=((r/c)*c+max(a,b))/min(a,b)-r/c;
				cnt-=fake1;
				cnt+=k1;
			}
			if((l/c)*c+max(a,b)>l&&al>0)
			{
				ll k1;
				fake2=(l/c)*c+max(a,b)-l;
				cnt-=fake2;
			}
			ll ans;
			ans=(r-l)-cnt;
			if(al==0)
			{
				ll l1;
				l1=max(l,max(a,b));
				if(a!=b&&r==max(a,b))
				ans=1;
				else if(a!=b&&l==r&&l>max(a,b))
				ans=1;
				else if((l1>r))
				ans=0;
				else
				ans=(r-l1+1);
			}
			cout<<ans<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
ll pre[4009];
void build(ll a,ll b)
{
	ll k=a*b;
	for(int i=1;i<=k;i++)
	{
		if((i%a)%b!=(i%b)%a)
		pre[i]=pre[i-1]+1;
		else
		pre[i]=pre[i-1];
	}
}
ll query(ll r,ll l,ll a,ll b)
{
	ll k1,k2,rem1,rem2;
	k1=r/(a*b);
	rem1=r%(a*b);
	k2=l/(a*b);
	rem2=l%(a*b);
	ll ans;
	ans=pre[a*b]*(k1-k2)+pre[rem1]-pre[rem2];
	return ans;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,q;
		cin>>a>>b;
		build(a,b);
		cin>>q;
		while(q--)
		{
			ll l,r,cnt;
			cin>>l>>r;
			cnt=query(r,l-1,a,b);
			cout<<cnt<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
ll pre[40009];
void build(ll a,ll b)
{
	ll k=a*b;
	for(int i=1;i<=k;i++)
	{
		if((i%a)%b!=(i%b)%a)
		pre[i]=pre[i-1]+1;
		else
		pre[i]=pre[i-1];
	}
}
ll query(ll r,ll l,ll a,ll b)
{
	ll k1,k2,rem1,rem2;
	k1=r/(a*b);
	rem1=r%(a*b);
	k2=l/(a*b);
	rem2=l%(a*b);
	ll ans;
	ans=pre[a*b]*(k1-k2)+pre[rem1]-pre[rem2];
	return ans;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,q;
		cin>>a>>b;
		build(a,b);
		cin>>q;
		while(q--)
		{
			ll l,r,cnt;
			cin>>l>>r;
			cnt=query(r,l-1,a,b);
			cout<<cnt<<" ";
		}
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,c,q,y;
		cin>>a>>b>>q;
		y=__gcd(a,b);
		c=(a*b)/y;
		while(q--)
		{
			ll l,r,ans=0,k,k1;
			cin>>l>>r;
			l=max(l,max(a,b));
			r=max(r,max(a,b));
			if(l>=r)
			ans=0;
			else
			{
				ll fake=0,rem=0,k1,k2;
				k2=r/c-l/c;
				fake+=k2*(max(a,b));
				if(k2==0)
				{
				rem=(r-l+1);
				ans=rem;
			    }
				else
				{
					if((r/c)*c+(max(a,b)-1)>r)
					rem=r-(r/c)*c-max(a,b)+1;
					ans=r-l-fake-rem;
					ll fake1;
					fake1=(r-(r/c)*c)/min(a,b);
					ans+=min(fake1,max(a,b)/min(a,b));
				}

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


#include<bits/stdc++.h>
using namespace std;
# define pb push_back
# define FOR(i,a,n) for(int i=a;i<n;i++)
# define mp make_pair
# define RFOR(i,a,n) for(int i=n;i>a;i--)
# define pii pair<long long int,long long int>
#define ub upper_bound
#define lb lower_bound
#define MOD 1000000007
typedef long long int ll;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t ;
	cin>>t;
	while(t--)
	{
		ll a,b,q,c;
		cin>>a>>b>>q;
		c=(a*b)/__gcd(a,b);
		while(q--)
		{
			ll l,r;
			cin>>l>>r;
			ll al,cnt=0,fake1,fake2;
			al=r/c-l/c;
			cnt=al*(max(a,b)-max(a,b)/min(a,b));

			if((r/c)*c+max(a,b)>r&&al>0)
			{
				fake1=(r/c)*c+max(a,b)-r;
				cnt-=fake1;
			}
			if((l/c)*c+max(a,b)>l&&al>0)
			{
				fake2=(l/c)*c+max(a,b)-l;
				cnt-=fake2;
			}
			ll ans;
			ans=(r-l)-cnt;
			if(al==0)
			{
				ll l1;
				l1=max(l,max(a,b));
				if(a!=b&&r==max(a,b))
				ans=1;
				else if((l1>=r))
				ans=0;
				else
				ans=(r-l1+1);
			}
			cout<<ans<<" ";
		}
		cout<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans,flag2=0;
        cin >> l>>r;
        long long   int x=(l%(a*b)),y=(r%(a*b)),z=(r-l)/(a*b+1);
        if((x%a)%b
        !=(x%b)%a)
        flag2=1;
        int flag=0;
      /*  cout<<z<<" "<<c[a*b-1]<<" ";
        cout<<c[y]-c[x]<<"\n";*/
    ans=z*(c[a*b-1]+flag);
    if(x<=y)
    {
        ans+=(c[y]-c[x]);
        if(flag2)
        ans+=1;
    }
    else
   { ans+=(c[y]+c[a*b-1]-c[x]);
        if(flag2)
        ans+=1;
   }
    cout<<ans<<" ";
    }
    cout<<"\n";
    }}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans,flag2=0;
        cin >> l>>r;
        long long   int x=(l%(a*b)),y=(r%(a*b)),z=(r-l)/(a*b+1);
        if((x%a)%b
        !=(x%b)%a)
        flag2=1;
        int flag=0;
        if(flag2)
        flag=1;

    ans=z*(c[a*b-1]+flag);
    if(x<=y)
    {
        ans+=(c[y]-c[x]);
        if(z==0)
        {if(flag2)
            ans++;
        }
    }
    else
   { ans+=(c[y]+c[a*b-1]-c[x]);
        if(z==0)
        {if(flag2)
            ans++;
        }
   }
    cout<<ans<<" ";
    }
    cout<<"\n";
    }}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans;
        cin >> l>>r;
        long long   int x=(l%(a*b)),y=(r%(a*b)),z=(r-l)/(a*b+1);
        int flag=0;
        if(c[x])
        flag=1;

    ans=z*(c[a*b-1]+flag);
    if(x<=y)
    {
        ans+=(c[y]-c[x]);
        if(z==0)
        {if(c[x])
            ans++;
        }
    }
    else
   { ans+=(c[y]+c[a*b-1]-c[x]);
        if(z==0)
        {if(c[x])
            ans++;
        }
   }
    cout<<ans<<" ";
    }
    cout<<"\n";
    }}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans,flag2=0;
        cin >> l>>r;
        long long   int x=(l%(a*b)),y=(r%(a*b)),z=(r-l)/(a*b+1);
        if((x%a)%b
        !=(x%b)%a)
        flag2=1;
        int flag=0;

    ans=z*(c[a*b-1]+flag);
    if(x<=y)
    {
        ans+=(c[y]-c[x]);
        if(flag2)
        ans+=z+1;
    }
    else
   { ans+=(c[y]+c[a*b-1]-c[x]);
        if(flag2)
        ans+=z+1;
   }
    cout<<ans<<" ";
    }
    cout<<"\n";
    }}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans1,ans2;
        cin >> l>>r;
        long long   int x=(l%(a*b)),y=(r%(a*b)),z=(r-l)/(a*b);
        ans1=c[a*b-1]*((l-1)/(a*b))+c[(l-1)%(a*b)];
        ans2=c[a*b-1]*((r)/(a*b))+c[(r)%(a*b)];
        cout<<ans2-ans1<<" ";
    }
    cout<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans,flag2=0;
        cin >> l>>r;
        long long int k=(a*b)*(l/(a*b)+1),j=(a*b)*(r/(a*b));
        if(j<k)
        {int x=(l)%(a*b),y=r%(a*b);
            if(x-1==-1)
            {cout<<c[y]<<" ";}
            else
            {cout<<c[y]-c[x-1]<<" ";}
        }
        else
        {int x=(l)%(a*b),y=r%(a*b); long long int ans=0;
            if(x-1==-1)
            {ans+=c[a*b-1];}
            else
            {ans+=c[a*b-1-(x-1)];}
            ans+=((j-k)/(a*b))*(c[a*b-1]);
            ans+=c[y];
            cout<<ans<<" ";
    }}
    cout<<"\n";
    }}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans;
        cin >> l>>r;
        long long   int x=(l%(a*b)),y=(r%(a*b)),z=(r-l)/(a*b);

        if(x!=0)
        x--;
        else
        x=a*b-1;
    ans=z*(c[a*b-1]);
    if(x<=y)
    {ans+=(c[y]-c[x]);}
    else
    ans+=(c[y]+c[a*b-1]-c[x]);
    cout<<ans<<" ";
    }
    cout<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans,flag2=0;
        cin >> l>>r;
        long long int k=(a*b)*(l/(a*b)+1),j=(a*b)*(r/(a*b));
        if(j<k)
        {int x=(l)%(a*b),y=r%(a*b);
            if(x-1==-1)
            {cout<<c[y]<<" ";}
            else
            {cout<<c[y]-c[x-1]<<" ";}
        }
        else
        {int x=(l)%(a*b),y=r%(a*b); long long int ans=0;
            if(x-1==-1)
            {ans+=c[a*b-1];}
            else
            {ans+=c[a*b-1]-c[x-1];}
            ans+=((j-k)/(a*b))*(c[a*b-1]);
            ans+=c[y];
            cout<<ans<<" ";
    }}
    cout<<"\n";
    }}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if((i%a)%b!=(i%b)%a)
    sum++;
    c[i]=sum;
    }
    for(int i=0;i<q;++i)
    {long long int l,r,ans;
        cin >> l>>r;
        int x=(l%(a*b)),y=(r%(a*b)),z=(r-l)/(a*b);

        if(x!=0)
        x--;
        else
        x=a*b-1;
    ans=z*(c[a*b-1]);
    if(x<=y)
    {ans+=(c[y]-c[x]);}
    else
    ans+=(c[y]+c[a*b-1]-c[x]);
    cout<<ans<<" ";
    }
    cout<<"\n";
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans,flag2=0;
        cin >> l>>r;
        long long int k=(a*b)*(l/(a*b)+1),j=(a*b)*(r/(a*b));
        if(j<k)
        {int x=(l-1)%(a*b),y=r%(a*b);
            if(x-1==-1)
            {cout<<c[y]<<" ";}
            else
            {cout<<c[y]-c[x-1]<<" ";}
        }
        else
        {int x=(l-1)%(a*b),y=r%(a*b); long long int ans=0;
            if(x-1==-1)
            {ans+=c[a*b-1];}
            else
            {ans+=c[a*b-1-(x-1)];}
            ans+=((j-k)/(a*b))*(c[a*b-1]);
            ans+=c[y];
            cout<<ans<<" ";
    }
    cout<<"\n";
    }}}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans,flag2=0;
        cin >> l>>r;
        long long   int x=(l%(a*b)),y=(r%(a*b)),z=(r-l)/(a*b+1);
        if((x%a)%b==(x%b)%a)
        flag2=1;
        int flag=0;
        if(flag2)
        flag=1;

    ans=z*(c[a*b-1]+flag);
    if(x<=y)
    {
        ans+=(c[y]-c[x]);
        if(z==0)
        {if(flag2)
            ans++;
        }
    }
    else
   { ans+=(c[y]+c[a*b-1]-c[x]);
        if(z==0)
        {if(flag2)
            ans++;
        }
   }
    cout<<ans<<" ";
    }
    cout<<"\n";
    }}


#include<bits/stdc++.h>
using namespace std;
int main()
{int t;
    cin >> t;
    for(int i=0;i<t;++i)
    {int a,b,q;
        cin >> a>>b>>q;
    int c[a*b];
    int sum=0;
    for(int i=0;i<a*b;++i)
    {if(((i%a)%b)!=((i%b)%a))
    sum++;
    c[i]=sum;
    }

    for(int i=0;i<q;++i)
    {long long int l,r,ans;
        cin >> l>>r;
        long long   int x=(l%(a*b)),y=(r%(a*b)),z=(r-l)/(a*b+1);
        int flag=0;
        if(c[x])
        flag=1;

    ans=z*(c[a*b-1]+flag);
    if(x<=y)
    {ans+=(c[y]-c[x]);}
    else
    ans+=(c[y]+c[a*b-1]-c[x]);
    cout<<ans<<" ";
    }
    cout<<"\n";
    }
}


#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/*int fastread(){
    int x=0;
    int c=getchar_unlocked();
    while(c<48)
        c=getchar_unlocked();
    while(c>=48){
        x=x*10+(c-48);
        c=getchar_unlocked();
    }

    return x;
}
ll count(ll n){
    ll c=0;
    while(n){
        n=n/10;
        c++;
    }
    return c;
}*/
ll countDivisibles(ll A, ll B, ll M)
{
    if (A % M == 0)
        return (B / M) - (A / M) + 1;

    // A is not divisible by M
    return (B / M) - (A / M);
}
int main() {
    boost
   ll t;
   cin>>t;
   while(t--){
       ll a,b,q;
       cin>>a>>b>>q;
       ll a1=__gcd(a,b);
       ll lcm=(a*b)/a1;
       //cout<<lcm<<"#";
       for(ll i=0;i<q;i++){
           ll ans=0;
           ll x,y;
           cin>>x>>y;
           if(y<lcm){
               ll d=0;
               for(ll i=x;i<=y;i++){
                   if(((i%a)%b)!=((i%b)%a))
                   d++;
               }
               cout<<d<<" ";
           }
           else if(a==b)
           cout<<0<<" ";
           else{
               ll p=x,q=y,p1=0,q1=0;
               while(p%lcm!=0){
               p++;}
               while(q%lcm!=0){
               q--;}
               {
               ll e=countDivisibles(p,q-1,lcm);
               ll d=max(a,b)*e;
               for(ll i=x;i<=p;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
               for(ll i=q;i<=y;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
             //  if(p==q)
               cout<<(y-x+2)-d<<" ";

               }
           }

       }
       cout<<endl;
   }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/*int fastread(){
    int x=0;
    int c=getchar_unlocked();
    while(c<48)
        c=getchar_unlocked();
    while(c>=48){
        x=x*10+(c-48);
        c=getchar_unlocked();
    }

    return x;
}
ll count(ll n){
    ll c=0;
    while(n){
        n=n/10;
        c++;
    }
    return c;
}*/
ll countDivisibles(ll A, ll B, ll M)
{
    if (A % M == 0)
        return (B / M) - (A / M) + 1;

    // A is not divisible by M
    return (B / M) - (A / M);
}
int main() {
    boost
   ll t;
   cin>>t;
   while(t--){
       ll a,b,q;
       cin>>a>>b>>q;
       ll x=__gcd(a,b);
       ll lcm=(a*b)/x;
       //cout<<lcm<<"#";
       for(ll i=0;i<q;i++){
           ll ans=0;
           ll x,y;
           cin>>x>>y;
           if(y<lcm){
               ll d=0;
               for(ll i=x;i<=y;i++){
                   if(((i%a)%b)!=((i%b)%a))
                   d++;
               }
               cout<<d<<" ";
           }
           else if(a==b)
           cout<<0<<" ";
           else{
               ll p=x,q=y,p1=0,q1=0;
               while(p%lcm!=0){
               p++;}
               while(q%lcm!=0){
               q--;}
               {
               ll e=countDivisibles(p,q-1,lcm);
               ll d=max(a,b)*e;
               for(ll i=x;i<=p;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
               for(ll i=q;i<=y;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
             //  if(p==q)
               cout<<(y-x+2)-d<<" ";

               }
           }

       }
       cout<<endl;
   }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/*int fastread(){
    int x=0;
    int c=getchar_unlocked();
    while(c<48)
        c=getchar_unlocked();
    while(c>=48){
        x=x*10+(c-48);
        c=getchar_unlocked();
    }

    return x;
}
ll count(ll n){
    ll c=0;
    while(n){
        n=n/10;
        c++;
    }
    return c;
}*/

int main() {
    boost
   ll t;
   cin>>t;
   while(t--){
   ll a,b,q,an=0;
   cin>>a>>b>>q;
   ll d=__gcd(a,b);
   ll lcm=(a*b)/d;
   ll e[(a*b)+1]={0};
   for(ll i=1;i<=(lcm);i++){
           if(((i%a)%b)!=((i%b)%a)){an++;
               e[i]=an;
           }
   }

   while(q--){
       ll l,r,ar,al;
       cin>>l>>r;
       ar=an*(r/(lcm));al=an*(l/(lcm));
       r=r%(lcm);l=l%(lcm);
       ar+=e[r];al+=e[l-1];
           cout<<abs(ar-al)<<" ";
   }
   cout<<endl;

   }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/*int fastread(){
    int x=0;
    int c=getchar_unlocked();
    while(c<48)
        c=getchar_unlocked();
    while(c>=48){
        x=x*10+(c-48);
        c=getchar_unlocked();
    }

    return x;
}
ll count(ll n){
    ll c=0;
    while(n){
        n=n/10;
        c++;
    }
    return c;
}*/
ll countDivisibles(ll A, ll B, ll M)
{
    if (A % M == 0)
        return (B / M) - (A / M) + 1;

    // A is not divisible by M
    return (B / M) - (A / M);
}
int main() {
    boost
   ll t;
   cin>>t;
   while(t--){
       ll a,b,q;
       cin>>a>>b>>q;
       ll x=__gcd(a,b);
       ll lcm=(a*b)/x;
       //cout<<lcm<<"#";
       for(ll i=0;i<q;i++){
           ll ans=0;
           ll x,y;
           cin>>x>>y;
           if(y<lcm){
               ll d=0;
               for(ll i=x;i<=y;i++){
                   if(((i%a)%b)!=((i%b)%a))
                   d++;
               }
               cout<<d<<" ";
           }
           else if(a==b)
           cout<<0<<" ";
           else{
               ll p=x,q=y;
               while(p%lcm!=0)
               p++;
               while(q%lcm!=0)
               q--;
               if(p==q){
                cout<<(y-x+1)-max(a,b)<<" ";
               }
               else{
               ll e=countDivisibles(p,q-1,lcm);
               ll d=max(a,b)*e;
               for(ll i=q;i<y;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
               cout<<(y-x+1)-d<<" ";
               }
           }

       }
       cout<<endl;
   }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/*int fastread(){
    int x=0;
    int c=getchar_unlocked();
    while(c<48)
        c=getchar_unlocked();
    while(c>=48){
        x=x*10+(c-48);
        c=getchar_unlocked();
    }

    return x;
}
ll count(ll n){
    ll c=0;
    while(n){
        n=n/10;
        c++;
    }
    return c;
}*/
ll countDivisibles(ll A, ll B, ll M)
{
    if (A % M == 0)
        return (B / M) - (A / M) + 1;

    // A is not divisible by M
    return (B / M) - (A / M);
}
int main() {
    boost
   ll t;
   cin>>t;
   while(t--){
       ll a,b,q;
       cin>>a>>b>>q;
       ll x=__gcd(a,b);
       ll lcm=(a*b)/x;
       //cout<<lcm<<"#";
       for(ll i=0;i<q;i++){
           ll ans=0;
           ll x,y;
           cin>>x>>y;
           if(y<lcm){
               ll d=0;
               for(ll i=x;i<=y;i++){
                   if(((i%a)%b)!=((i%b)%a))
                   d++;
               }
               cout<<d<<" ";
           }
           else if(a==b)
           cout<<0<<" ";
           else{
               ll p=x,q=y;
               while(p%lcm!=0)
               p++;
               while(q%lcm!=0)
               q--;
               if(p==q){
                   ll d=0;
                for(ll i=x;i<=y;i++){
                   if(((i%a)%b)!=((i%b)%a))
                   d++;
               }
               cout<<d<<" ";
               }
               else{
               ll e=countDivisibles(p,q-1,lcm);
               ll d=max(a,b)*e;
               for(ll i=x;i<p;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
               for(ll i=q;i<=y;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
               cout<<(y-x+1)-d<<" ";
               }
           }

       }
       cout<<endl;
   }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/*int fastread(){
    int x=0;
    int c=getchar_unlocked();
    while(c<48)
        c=getchar_unlocked();
    while(c>=48){
        x=x*10+(c-48);
        c=getchar_unlocked();
    }

    return x;
}
ll count(ll n){
    ll c=0;
    while(n){
        n=n/10;
        c++;
    }
    return c;
}*/
ll countDivisibles(ll A, ll B, ll M)
{
    if (A % M == 0)
        return (B / M) - (A / M) + 1;

    // A is not divisible by M
    return (B / M) - (A / M);
}
int main() {
    boost
   ll t;
   cin>>t;
   while(t--){
       ll a,b,q;
       cin>>a>>b>>q;
       ll a1=__gcd(a,b);
       ll lcm=(a*b)/a1;
       //cout<<lcm<<"#";
       for(ll i=0;i<q;i++){
           ll ans=0;
           ll x,y;
           cin>>x>>y;
           if(y<lcm){
               ll d=0;
               for(ll i=x;i<=y;i++){
                   if(((i%a)%b)!=((i%b)%a))
                   d++;
               }
               cout<<d<<" ";
           }
           else if(a==b)
           cout<<0<<" ";
           else{
               ll p=x,q=y,p1=0,q1=0;
               while(p%lcm!=0){
               p++;}
               while(q%lcm!=0){
               q--;}
               {
               ll e=countDivisibles(p,q-1,lcm);
               ll d=max(a,b)*e;
               for(ll i=x;i<=p;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
               for(ll i=q;i<=y;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
             //  if(p==q)
               cout<<(y-x+2)-d<<" ";

               }
           }

       }
       cout<<endl;
   }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/*int fastread(){
    int x=0;
    int c=getchar_unlocked();
    while(c<48)
        c=getchar_unlocked();
    while(c>=48){
        x=x*10+(c-48);
        c=getchar_unlocked();
    }

    return x;
}
ll count(ll n){
    ll c=0;
    while(n){
        n=n/10;
        c++;
    }
    return c;
}*/
ll countDivisibles(ll A, ll B, ll M)
{
    if (A % M == 0)
        return (B / M) - (A / M) + 1;

    // A is not divisible by M
    return (B / M) - (A / M);
}
int main() {
    boost
   ll t;
   cin>>t;
   while(t--){
       ll a,b,q;
       cin>>a>>b>>q;
       ll x=__gcd(a,b);
       ll lcm=(a*b)/x;
       //cout<<lcm<<"#";
       for(ll i=0;i<q;i++){
           ll ans=0;
           ll x,y;
           cin>>x>>y;
           if(y<lcm){
               ll d=0;
               for(ll i=x;i<=y;i++){
                   if(((i%a)%b)!=((i%b)%a))
                   d++;
               }
               cout<<d<<" ";
           }
           else if(a==b)
           cout<<0<<" ";
           else{
               ll p=x,q=y;
               while(p%lcm!=0)
               p++;
               while(q%lcm!=0)
               q--;
               if(p==q){
                cout<<(y-x+1)-max(a,b)<<" ";
               }
               else{
               ll e=countDivisibles(p,q-1,lcm);
               ll d=max(a,b)*e;
               for(ll i=x;i<p;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
               for(ll i=q;i<=y;i++){
                   if(((i%a)%b)==((i%b)%a))
                   d++;
               }
               cout<<(y-x+1)-d<<" ";
               }
           }

       }
       cout<<endl;
   }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
/*int fastread(){
    int x=0;
    int c=getchar_unlocked();
    while(c<48)
        c=getchar_unlocked();
    while(c>=48){
        x=x*10+(c-48);
        c=getchar_unlocked();
    }

    return x;
}
ll count(ll n){
    ll c=0;
    while(n){
        n=n/10;
        c++;
    }
    return c;
}*/

int main() {
    boost
   ll t;
   cin>>t;
   while(t--){
   ll a,b,q,an=0;
   cin>>a>>b>>q;
   ll d=__gcd(a,b);
   ll lcm=(a*b)/d;
   ll e[(a*b)+1]={0};
   for(ll i=1;i<=(lcm);i++){
           if(((i%a)%b)!=((i%b)%a)){an++;
               e[i]=an;
           }
   }

   while(q--){
       ll l,r,ar,al;
       cin>>l>>r;
       ar=an*(r/(lcm));al=an*((l-1)/(lcm));
       r=r%(lcm);l=((l-1)%(lcm));
       ar+=e[r];al+=e[l];
           cout<<(ar-al)<<" ";
   }
   cout<<endl;

   }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define lson l , m , rt << 1
#define rson m + 1 , r , rt << 1|1
typedef long long ll;
const ll N = 1e5+55;
const ll mod = 1000000007;
double add[N<<2],sum[N<<2];
struct node{
    int pos,h,l,r;
}a[N];
struct node2{
    int pos,val;
    bool friend operator < (node2 a,node2 b){
        return a.pos<b.pos;
    }
}b[N];
vector<int>v,v2;
int getid(int x){return lower_bound(v.begin(),v.end(),x)-v.begin()+1;}
int getid2(int x){return lower_bound(v2.begin(),v2.end(),x)-v2.begin()+1;}
void PushUp(int rt){
    sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
void PushDown(int rt,int m,int l,int r){
    if (fabs(add[rt])>0.00001){
        if(fabs(add[rt<<1])<0.00001)
            add[rt<<1]=add[rt];
        else
            add[rt<<1]*=add[rt];
        if(fabs(add[rt<<1|1])<0.00001)
            add[rt<<1|1]=add[rt];
        else
            add[rt<<1|1]*=add[rt];
        sum[rt<<1]*=add[rt];
        sum[rt<<1|1]*=add[rt];
        //printf("l:%d r:%d m:%d\n",l,r,m);
        //printf("lef:%f rig:%f\n",sum[rt<<1]);
        add[rt] = 0;
    }
}
void build(int l,int r,int rt){
    add[rt] = 0;
    sum[rt] = 0;
    if (l == r) {
        if(v2[getid2(v[l-1])-1]==v[l-1])
            sum[rt]=b[getid2(v[l-1])].val;
        else
            sum[rt]=0;
        return ;
    }
    int m = (l + r) >> 1;
    build(lson);
    build(rson);
    PushUp(rt);
}
void upedit(int L,int R,double c,int l,int r,int rt){
    if (L <= l && r <= R) {
        if(fabs(add[rt]-0)<0.00001)
            add[rt]=c;
        sum[rt]*=c;
        return ;
    }
    int m = (l + r)>>1;
    PushDown(rt,m,l,r);
    if (L <= m)
        upedit(L, R, c, lson);
    if (m < R)
        upedit(L, R, c, rson);
    PushUp(rt);
}
double query(int L,int R,int l,int r,int rt){
    if (L <= l && r <= R) {
        //printf("%d %d %f\n",l,r,sum[rt]);
        return sum[rt];
    }
    int m = (l + r) >> 1;
    PushDown(rt,m,l,r);
    double ret = 0;
    if (L <= m)
        ret += query(L, R, lson);
    if (m < R)
        ret += query(L, R, rson);
    return ret;
}
int main(){
    ios::sync_with_stdio(false), cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i].pos>>a[i].h>>a[i].l>>a[i].r;
        v.push_back(a[i].pos);
        v.push_back(a[i].pos+a[i].h);
        v.push_back(a[i].pos-a[i].h);
    }
    for(int i=1;i<=m;i++)
        cin>>b[i].pos>>b[i].val,v.push_back(b[i].pos),v2.push_back(b[i].pos);
    sort(b+1,b+m+1);
    sort(v.begin(),v.end()),v.erase(unique(v.begin(),v.end()),v.end());
    sort(v2.begin(),v2.end()),v2.erase(unique(v2.begin(),v2.end()),v2.end());
    int sz=v.size();
    build(1,sz,1);
    //printf("%.5f\n",sum[1]);
    for(int i=1;i<=n;i++){
        int L=getid(a[i].pos-a[i].h);
        int R=getid(a[i].pos+a[i].h);
        int M=getid(a[i].pos);
        if(R<1)
            continue;
        if(L<M){
            upedit(L,M,1-a[i].l*1.0/100,1,sz,1);
        }
        if(R>M)
            upedit(M,R,1-a[i].r*1.0/100,1,sz,1);
    }
    printf("%.5f\n",sum[1]);
    return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double
#define N 100001

struct Trees{
    int a,h;
    double l,r;
};
Trees trees[N];
bool comp(Trees t1,Trees t2)
{
    return t1.a < t2.a;
}
int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < n;i++)
    {
        cin >> trees[i].a >> trees[i].h >> trees[i].l >> trees[i].r ;
        trees[i].l /= (double)100;
        trees[i].r /= (double)100;
    }
    vector<int> mushrooms(m);
    double prob[m];

    for(int i = 0;i < m;i++)
    {
        int dumb;
        cin >> mushrooms[i] >> dumb;
        prob[i] = 1;
    }
    sort(mushrooms.begin(),mushrooms.end());
    sort(trees,trees + n,comp);
    int j = 0;
    set<pair<int,int>> s;
    double fall = 1;
    for(int i = 0;i < m;i++)
    {
        while(j < n and trees[j].a < mushrooms[i])
        {
            s.insert({trees[j].a + trees[j].h,j});
            fall *= (1-trees[j].r);
            j++;
        }
        while(!s.empty() and (*s.begin()).first < mushrooms[i])
        {
            fall /= (1-trees[(*s.begin()).second].r);
            s.erase(s.begin());
        }
        prob[i] = fall;
    }

    s.clear();
    j = n - 1;
    fall = 1;

    for(int i = m - 1;i >= 0;i--)
    {
        while(j >= 0 and trees[j].a > mushrooms[i])
        {
            s.insert({trees[j].a - trees[j].h,j});
            fall *= (1-trees[j].r);
            j--;
        }
        while(!s.empty() and (*s.begin()).first > mushrooms[i])
        {
            fall /= (1-trees[(*s.begin()).second].r);
            s.erase(s.begin());
        }
        prob[i] *= fall;
    }

    double ans = 0;
    for(int i = 0;i < m;i++)
    {
        ans += prob[i];
    }
    cout << fixed << setprecision(7);
    cout << ans;

}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double
#define N 100001

struct Trees{
    int a,h;
    double l,r;
};
Trees trees[N];
bool comp(Trees t1,Trees t2)
{
    return t1.a < t2.a;
}
double lazy[N];
double s[N];
void build(int id,int lo,int hi)
{
    if(lo == hi)
    {
        s[id] = 1;
        lazy[id] = 1;
        return ;
    }
    lazy[id] = 1;
    s[id] = 1;
    int mid = (lo + hi) >> 1;
    build(2*id,lo,mid);
    build(2*id+1,mid+1,hi);
}
void propogate(int id)
{
    if(lazy[id] != 1)
    {
        s[id] *= lazy[id];
        lazy[2*id] *= lazy[id];
        lazy[2*id + 1] *= lazy[id];
        lazy[id] = 1;
    }
}
void update(int id,int lo,int hi,int l,int r,double val)
{
    if(l > r)
        return;
    propogate(id);

    if(lo > r or hi < l)
        return;
    ////cerr << lo << " " << hi << " " << l << " " << r << " " << val << endl;
    if(lo >= l and  hi <= r)
    {
        s[id] *= val;
        lazy[2*id] *= val;
        lazy[2*id+1] *= val;
        return;
    }
    int mid = (lo + hi)>>1;
    update(2*id,lo,mid,l,r,val);
    update(2*id + 1,mid + 1,hi,l,r,val);
}
double query(int id,int lo,int hi,int pos)
{
    propogate(id);
    if(lo == hi)
    {
        return s[id];
    }
    int mid = (lo + hi) >> 1;
    if(pos <= mid)
        return query(2*id,lo,mid,pos);
    else
        return query(2*id + 1,mid + 1,hi,pos);
}
int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < n;i++)
    {
        cin >> trees[i].a >> trees[i].h >> trees[i].l >> trees[i].r ;
        trees[i].l /= (double)100;
        trees[i].r /= (double)100;
    }
    vector<pair<int,int>> mushrooms(m);

    for(int i = 0;i < m;i++)
    {
        cin >> mushrooms[i].first >> mushrooms[i].second;
    }

    sort(mushrooms.begin(),mushrooms.end());
    sort(trees,trees + n,comp);
    build(1,1,m);

    for(int i = 0;i < n;i++)
    {
        int xmax = trees[i].a + trees[i].h;
        int xmin = trees[i].a + 1;
        int posr = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(xmax + 1,(ll)0)) - mushrooms.begin();

        posr--;
        int posl = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(xmin,(ll)0)) - mushrooms.begin();
        //cerr << posl << " " << posr << " " << (1 - trees[i].r) <<  endl;

        update(1,1,m,posl + 1,posr + 1,(1-trees[i].r));
        //cerr << query(1,1,m,1) << endl;

        posr = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(trees[i].a,(ll)0)) - mushrooms.begin();
        posr-- ;
        posl = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(trees[i].a - trees[i].h,(ll)0)) - mushrooms.begin();
        update(1,1,m,posl + 1,posr + 1,(1-trees[i].l));
        //cerr << posl << " " << posr << " " << (1-trees[i].l) <<  endl;
    }

    double ans = 0;
    for(int i = 1;i <= m;i++)
    {
        //cerr << query(1,1,m,i) << " " << mushrooms[i - 1].first << endl;
        ans += query(1,1,m,i) * mushrooms[i - 1].second;
    }
    cout << fixed << setprecision(7);
    cout << ans;

}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double
#define N 100001

struct Trees{
    int a,h;
    double l,r;
};
Trees trees[N];
bool comp(Trees t1,Trees t2)
{
    return t1.a < t2.a;
}
double lazy[N];
double s[N];
void build(int id,int lo,int hi)
{
    if(lo == hi)
    {
        s[id] = 1;
        lazy[id] = 1;
        return ;
    }
    lazy[id] = 1;
    s[id] = 1;
    int mid = (lo + hi) >> 1;
    build(2*id,lo,mid);
    build(2*id+1,mid+1,hi);
}
void propogate(int id)
{
    if(lazy[id] != 1)
    {
        s[id] *= lazy[id];
        lazy[2*id] *= lazy[id];
        lazy[2*id + 1] *= lazy[id];
        lazy[id] = 1;
    }
}
void update(int id,int lo,int hi,int l,int r,double val)
{
    if(l > r)
        return;
    propogate(id);

    if(lo > r or hi < l)
        return;
    if(lo >= l and  hi <= r)
    {
        s[id] *= val;
        lazy[2*id] *= val;
        lazy[2*id+1] *= val;
        return;
    }
    int mid = (lo + hi)>>1;
    update(2*id,lo,mid,l,r,val);
    update(2*id + 1,mid + 1,hi,l,r,val);
}
double query(int id,int lo,int hi,int pos)
{
    propogate(id);
    if(lo == hi)
    {
        return s[id];
    }
    int mid = (lo + hi) >> 1;
    if(pos <= mid)
        return query(2*id,lo,mid,pos);
    else
        return query(2*id + 1,mid + 1,hi,pos);
}
int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < n;i++)
    {
        cin >> trees[i].a >> trees[i].h >> trees[i].l >> trees[i].r ;
        trees[i].l /= (double)100;
        trees[i].r /= (double)100;
    }
    vector<pair<int,int>> mushrooms(m);

    for(int i = 0;i < m;i++)
    {
        cin >> mushrooms[i].first >> mushrooms[i].second;
    }

    sort(mushrooms.begin(),mushrooms.end());
    sort(trees,trees + n,comp);
    build(1,1,m);

    for(int i = 0;i < n;i++)
    {
        int xmax = trees[i].a + trees[i].h;
        int xmin = trees[i].a + 1;

        int posr = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(xmax + 1,(ll)0)) - mushrooms.begin();
        posr--;
        int posl = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(xmin,(ll)0)) - mushrooms.begin();

        update(1,1,m,posl + 1,posr + 1,(1-trees[i].r));

        posr = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(trees[i].a,(ll)0)) - mushrooms.begin();
        posr-- ;
        posl = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(trees[i].a - trees[i].h,(ll)0)) - mushrooms.begin();

        update(1,1,m,posl + 1,posr + 1,(1-trees[i].l));
    }

    double ans = 0;
    for(int i = 1;i <= m;i++)
    {
        ans += query(1,1,m,i) * mushrooms[i - 1].second;
    }
    cout << fixed << setprecision(7);
    cout << ans;

}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double
#define N 100001

struct Trees{
    int a,h;
    double l,r;
};
Trees trees[N];
bool comp(Trees t1,Trees t2)
{
    return t1.a < t2.a;
}
double lazy[N];
double s[N];
void build(int id,int lo,int hi)
{
    if(lo == hi)
    {
        s[id] = 1;
        lazy[id] = 1;
        return ;
    }
    lazy[id] = 1;
    s[id] = 1;
    int mid = (lo + hi) >> 1;
    build(2*id,lo,mid);
    build(2*id+1,mid+1,hi);
}
void propogate(int id)
{
    if(lazy[id] != 1)
    {
        s[id] *= lazy[id];
        lazy[2*id] *= lazy[id];
        lazy[2*id + 1] *= lazy[id];
        lazy[id] = 1;
    }
}
void update(int id,int lo,int hi,int l,int r,double val)
{
    if(l > r)
        return;
    propogate(id);

    if(lo > r or hi < l)
        return;
    ////cerr << lo << " " << hi << " " << l << " " << r << " " << val << endl;
    if(lo >= l and  hi <= r)
    {
        s[id] *= val;
        lazy[2*id] *= val;
        lazy[2*id+1] *= val;
        return;
    }
    int mid = (lo + hi)>>1;
    update(2*id,lo,mid,l,r,val);
    update(2*id + 1,mid + 1,hi,l,r,val);
}
double query(int id,int lo,int hi,int pos)
{
    propogate(id);
    if(lo == pos)
    {
        return s[id];
    }
    int mid = (lo + hi) >> 1;
    if(pos <= mid)
        return query(2*id,lo,mid,pos);
    else
        return query(2*id + 1,mid + 1,hi,pos);
}
int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < n;i++)
    {
        cin >> trees[i].a >> trees[i].h >> trees[i].l >> trees[i].r ;
        trees[i].l /= (double)100;
        trees[i].r /= (double)100;
    }
    vector<pair<int,int>> mushrooms(m);

    for(int i = 0;i < m;i++)
    {
        cin >> mushrooms[i].first >> mushrooms[i].second;
    }

    sort(mushrooms.begin(),mushrooms.end());
    sort(trees,trees + n,comp);
    build(1,1,m);

    for(int i = 0;i < n;i++)
    {
        int xmax = trees[i].a + trees[i].h;
        int xmin = trees[i].a + 1;
        int posr = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(xmax + 1,(ll)0)) - mushrooms.begin();

        posr--;
        int posl = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(xmin,(ll)0)) - mushrooms.begin();
        //cerr << posl << " " << posr << " " << (1 - trees[i].r) <<  endl;

        update(1,1,m,posl + 1,posr + 1,(1-trees[i].r));
        //cerr << query(1,1,m,2) << endl;

        posr = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(trees[i].a,(ll)0)) - mushrooms.begin();
        posr-- ;
        posl = upper_bound(mushrooms.begin(),mushrooms.end(),make_pair(trees[i].a - trees[i].h,(ll)0)) - mushrooms.begin();
        update(1,1,m,posl + 1,posr + 1,(1-trees[i].l));
        //cerr << posl << " " << posr << endl;
    }

    double ans = 0;
    for(int i = 1;i <= m;i++)
    {
        //cerr << query(1,1,m,i) << " " << mushrooms[i - 1].first << endl;
        ans += query(1,1,m,i) * mushrooms[i - 1].second;
    }
    cout << fixed << setprecision(7);
    cout << ans;

}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double
#define N 100001

struct Trees{
    int a,h;
    double l,r;
};
Trees trees[N];
bool comp(Trees t1,Trees t2)
{
    return t1.a < t2.a;
}
int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int n,m;
    cin >> n >> m;
    for(int i = 0;i < n;i++)
    {
        cin >> trees[i].a >> trees[i].h >> trees[i].l >> trees[i].r ;
        trees[i].l /= (double)100;
        trees[i].r /= (double)100;
    }
    vector<pair<int,int>> mushrooms(m);
    double prob[m];

    for(int i = 0;i < m;i++)
    {
        cin >> mushrooms[i].first >> mushrooms[i].second;
        prob[i] = 1;
    }
    sort(mushrooms.begin(),mushrooms.end());
    sort(trees,trees + n,comp);
    int j = 0;
    set<pair<int,int>> s;
    double fall = 1;
    for(int i = 0;i < m;i++)
    {
        while(j < n and trees[j].a < mushrooms[i].first)
        {
            s.insert({trees[j].a + trees[j].h,j});
            fall *= (1-trees[j].r);
            j++;
        }
        while(!s.empty() and (*s.begin()).first < mushrooms[i].first)
        {
            fall /= (1-trees[(*s.begin()).second].r);
            s.erase(s.begin());
        }
        prob[i] = fall;
    }

    s.clear();
    j = n - 1;
    fall = 1;

    for(int i = m - 1;i >= 0;i--)
    {
        while(j >= 0 and trees[j].a > mushrooms[i].first)
        {
            s.insert({trees[j].a - trees[j].h,j});
            fall *= (1-trees[j].l);
            j--;
        }
        while(!s.empty() and (*s.begin()).first > mushrooms[i].first)
        {
            fall /= (1-trees[(*s.begin()).second].l);
            s.erase(s.begin());
        }
        prob[i] *= fall;
    }

    double ans = 0;
    for(int i = 0;i < m;i++)
    {
        ans += prob[i] * mushrooms[i].second;
    }
    cout << fixed << setprecision(7);
    cout << ans;

}


// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/

#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const int N = 1e5 + 199;

lld t[4*N];
lld combine(lld a, lld b) {
    return a * b;
}

void build(int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = 1.0;
    } else {
        int tm = (tl + tr) / 2;
        build(v*2, tl, tm);
        build(v*2+1, tm+1, tr);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}

void update(int v, int tl, int tr, int pos, lld new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}

struct event {
    int a, h, l, r, s, ind;
};

int n, m;

map<int, vector<event>> sweepin, sweepout, sweepoutleft;
map<int, vector<pii>> shrooms;

lld ans[N];

int solve() {
    cin >> n >> m;
    set<int> all;
    for (int i = 1; i <= n; i++) {
        int a, h, l, r;
        cin >> a >> h >> l >> r;
        int s = 100 - l - r;
        sweepin[a].push_back({a, h, l, r, s, i});
        sweepout[a + h].push_back({a, h, l, r, s, i});
        sweepoutleft[a - h].push_back({a, h, l, r, s, i});
        all.insert(a);
        all.insert(a + h);
        all.insert(a - h);
    }
    build(1, 1, n);
    for (int i = 1; i <= m; i++) {
        int b, z;
        cin >> b >> z;
        shrooms[b].push_back({z, i});
        ans[i] = z;
        all.insert(b);
    }
    for (auto i : all) {
        for (auto j : sweepin[i]) {
            lld fallinleft = (j.l + j.s) / 100.00;
            update(1, 1, n, j.ind, fallinleft);
        }

        for (auto s : shrooms[i]) {
            ans[s.se] *= t[1];
        }

        for (auto j : sweepout[i]) {
            update(1, 1, n, j.ind, 1.0);
        }
    }
    build(1, 1, n);
    for (auto it = all.rbegin(); it != all.rend(); it++) {
        int i = *it;
        for (auto j : sweepin[i]) {
            lld fallinright = (j.r + j.s) / 100.00;
            update(1, 1, n, j.ind, fallinright);
        }
        for (auto s : shrooms[i]) {
            ans[s.se] *= t[1];
        }

        for (auto j : sweepoutleft[i]) {
            update(1, 1, n, j.ind, 1.0);
        }
    }

    lld final_ans = 0.0;
    for (int i = 1; i <= m; i++) {
        final_ans += ans[i];
    }

    cout << fixed << setprecision(12) << final_ans << endl;

    return 0;

}

int32_t main(){ _
    int t;
    // cin >> t;
    t = 1;
    while (t--) solve();
}


// g++ -std=c++14

/*

Today might be the chance to grasp the chance to let your talent bloom.
May be tomorrow, the day after, or next year...
May be even when you are 30. I'm not sure if physique has anything to do with it
but if you think that it will never come, it probably never will.

- Tooru Oikawa.

*/

#include<bits/stdc++.h>

typedef long long ll;
typedef long double lld;
using namespace std;

#define endl "\n"
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define __ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(c) c.begin(),c.end()
#define pii pair<int, int>
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
template<typename S, typename T>
ostream& operator<<(ostream& out,pair<S,T> const& p){out<<'('<<p.fi<<", "<<p.se<<')';return out;}

template<typename T>
ostream& operator<<(ostream& out,vector<T> const& v){
ll l=v.size();for(ll i=0;i<l-1;i++)out<<v[i]<<' ';if(l>0)out<<v[l-1];return out;}

template <typename T>
ostream &operator<<(ostream &out, set<T> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << (*i) << ' ';
    return out;
}
template <typename T, typename V>
ostream &operator<<(ostream &out, map<T, V> const &v) {
    for (auto i = v.begin(); i != v.end(); i++)
        out << "\n" << (i->first) <<  ":"  << (i->second);
    return out;
}

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}

template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}

const int N = 1e5 + 199;

lld t[4*N];
lld combine(lld a, lld b) {
    return a * b;
}

void build(int v, int tl, int tr) {
    if (tl == tr) {
        t[v] = 1.0;
    } else {
        int tm = (tl + tr) / 2;
        build(v*2, tl, tm);
        build(v*2+1, tm+1, tr);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}

void update(int v, int tl, int tr, int pos, lld new_val) {
    if (tl == tr) {
        t[v] = new_val;
    } else {
        int tm = (tl + tr) / 2;
        if (pos <= tm)
            update(v*2, tl, tm, pos, new_val);
        else
            update(v*2+1, tm+1, tr, pos, new_val);
        t[v] = combine(t[v*2], t[v*2+1]);
    }
}

struct event {
    int a, h, l, r, s, ind;
};

int n, m;

map<int, vector<event>> sweepin, sweepout, sweepoutleft;
map<int, vector<pii>> shrooms;

lld ans[N];

int solve() {
    cin >> n >> m;
    set<int> all;
    for (int i = 1; i <= n; i++) {
        int a, h, l, r;
        cin >> a >> h >> l >> r;
        int s = 100 - l - r;
        sweepin[a].push_back({a, h, l, r, s, i});
        sweepout[a + h].push_back({a, h, l, r, s, i});
        sweepoutleft[a - h].push_back({a, h, l, r, s, i});
        all.insert(a);
        all.insert(a + h);
        all.insert(a - h);
    }
    build(1, 1, n);
    for (int i = 1; i <= m; i++) {
        int b, z;
        cin >> b >> z;
        shrooms[b].push_back({z, i});
        ans[i] = z;
        all.insert(b);
    }
    for (auto i : all) {
        for (auto s : shrooms[i]) {
            ans[s.se] *= t[1];
        }
        for (auto j : sweepin[i]) {
            lld fallinleft = (j.l + j.s + 0.00) / 100.00;
            update(1, 1, n, j.ind, fallinleft);
        }

        for (auto j : sweepout[i]) {
            update(1, 1, n, j.ind, 1.0);
        }
    }
    build(1, 1, n);
    for (auto it = all.rbegin(); it != all.rend(); it++) {
        int i = *it;
        for (auto s : shrooms[i]) {
            ans[s.se] *= t[1];
        }
        for (auto j : sweepin[i]) {
            lld fallinright = (j.r + j.s + 0.00) / 100.00;
            update(1, 1, n, j.ind, fallinright);
        }

        for (auto j : sweepoutleft[i]) {
            update(1, 1, n, j.ind, 1.0);
        }
    }

    lld final_ans = 0.0;
    for (int i = 1; i <= m; i++) {
        final_ans += ans[i];
    }

    cout << fixed << setprecision(12) << final_ans << endl;

    return 0;

}

int32_t main(){ _
    int t;
    // cin >> t;
    t = 1;
    while (t--) solve();
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
const int N=1e5+10;
int n, m;
typedef pair<ll, double>  pld;
typedef pair<ll, ll> pll;
vector<pair<pll, double> > tl, tr;
vector<pii> mush;
priority_queue<pld, vector<pld>, greater<pld> > q1;
priority_queue<pld, vector<pld>, less<pld> > q2;
double ans;
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 0, n){
		int a, h, l, r;
		scanf("%d%d%d%d", &a, &h, &l, &r);
		tl.pb(mp(mp((0LL+a-1), (0LL+a-h)), 1.*(100-l)/100));
		tl.pb(mp(mp((0LL+a+h), (0LL+a+1)), 1.*(100-r)/100));
	}
	rep(i, 0, m){
		int b, z;
		scanf("%d%d", &b, &z);
		mush.pb(mp(b, z));
	}
	sort(tl.begin(), tl.end());
	sort(mush.begin(), mush.end());
	int p1, p2;
	double p=1;
	for(p1=0, p2=0; p2<m; p2++){
		ll pos=mush[p2].fi;
		while(p1<sz(tl)&&tl[p1].fi.fi<pos)p1++;
		while(sz(q1)&&q1.top().fi<pos){
			pld t=q1.top();
			q1.pop();
			if(t.se)p/=t.se;
			if(!sz(q1))p=1;
		}
		while(p1<sz(tl)&&tl[p1].fi.fi>=pos&&tl[p1].fi.se<=pos){
			p*=tl[p1].se;
			q1.push(mp(tl[p1].fi.fi, tl[p1].se));
			p1++;
		}
		ans+=mush[p2].se*p;
	}
	printf("%.10f\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
const int N=1e5+10;
int n, m;
typedef pair<ll, double>  pld;
typedef pair<ll, ll> pll;
vector<pair<pll, ll> > tl, tr;
vector<pii> mush;
priority_queue<pll, vector<pll>, greater<pll> > q1;
priority_queue<pll, vector<pll>, greater<pll> > q2;
double ans;
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 0, n){
		int a, h, l, r;
		scanf("%d%d%d%d", &a, &h, &l, &r);
		tl.pb(mp(mp((0LL+a-h), (0LL+a-1)), 100-l));
		tl.pb(mp(mp((0LL+a+1), (0LL+a+h)), 100-r));
	}
	rep(i, 0, m){
		int b, z;
		scanf("%d%d", &b, &z);
		mush.pb(mp(b, z));
	}
	sort(tl.begin(), tl.end());
	sort(mush.begin(), mush.end());
	int p1, p2;
	double p=0;
	int cnt=0;
	for(p1=0, p2=0; p2<m; p2++){
		ll pos=mush[p2].fi;
		while(sz(q1)&&q1.top().fi<pos){
			pld t=q1.top();
			q1.pop();
			if(t.se==0)cnt--;
			if(t.se)p-=log(t.se)-log(100);
		}
		while(p1<sz(tl)&&tl[p1].fi.fi<=pos){
			if(tl[p1].fi.se>=pos){
				if(tl[p1].se==0)
					cnt++;
				else{
					p+=log(tl[p1].se)-log(100);
				}
				q1.push(mp(tl[p1].fi.se, tl[p1].se));
			}
			p1++;
		}
		if(!cnt)ans+=mush[p2].se*exp(p);
	}
	printf("%.10f\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
const int N=1e5+10;
int n, m;
typedef pair<ll, double>  pld;
typedef pair<ll, ll> pll;
vector<pair<pll, double> > tl, tr;
vector<pii> mush;
priority_queue<pld, vector<pld>, greater<pld> > q1;
priority_queue<pld, vector<pld>, less<pld> > q2;
double ans;
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 0, n){
		int a, h, l, r;
		scanf("%d%d%d%d", &a, &h, &l, &r);
		tl.pb(mp(mp(0LL+a-h, 0LL+a-1), 1.*(100-l)/100));
		tl.pb(mp(mp(0LL+a+1, 0LL+a+h), 1.*(100-r)/100));
	}
	rep(i, 0, m){
		int b, z;
		scanf("%d%d", &b, &z);
		mush.pb(mp(b, z));
	}
	sort(tl.begin(), tl.end());
	sort(mush.begin(), mush.end());
	int p1, p2, p3;
	double p=1;
	for(p1=0, p2=0; p2<m; p2++){
		int pos=mush[p2].fi;
		while(p1<sz(tl)&&tl[p1].fi.se<pos)p1++;

		while(sz(q1)&&q1.top().fi<pos){
			if(q1.top().se)p/=q1.top().se;
			q1.pop();
		}

		while(p1<sz(tl)&&tl[p1].fi.fi<=pos&&tl[p1].fi.se>=pos){
			if(tl[p1].se)p*=tl[p1].se;
			q1.push(mp(tl[p1].fi.se, tl[p1].se));
			p1++;
		}

		ans+=mush[p2].se*p;
	}
	printf("%.10f\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
const int N=1e5+10;
int n, m;
typedef pair<ll, double>  pld;
typedef pair<ll, ll> pll;
vector<pair<pll, double> > tl, tr;
vector<pii> mush;
priority_queue<pld, vector<pld>, greater<pld> > q1;
priority_queue<pld, vector<pld>, less<pld> > q2;
double ans;
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 0, n){
		int a, h, l, r;
		scanf("%d%d%d%d", &a, &h, &l, &r);
		tl.pb(mp(mp((0LL+a-1), (0LL+a-h)), 1.*(100-l)/100));
		tl.pb(mp(mp((0LL+a+h), (0LL+a+1)), 1.*(100-r)/100));
	}
	rep(i, 0, m){
		int b, z;
		scanf("%d%d", &b, &z);
		mush.pb(mp(b, z));
	}
	sort(tl.begin(), tl.end());
	sort(mush.begin(), mush.end());
	int p1, p2;
	double p=1;
	//fi r se l
	//rep(i, 0, sz(mush))cout<<mush[i].fi<<' '<<mush[i].se<<endl;
	//rep(i, 0, sz(tl)){
	//	cout<<tl[i].fi.fi<<' '<<tl[i].fi.se<<' '<<tl[i].se<<endl;
	//}
	int cnt=0;
	for(p1=0, p2=0; p2<m; p2++){
		ll pos=mush[p2].fi;
		while(p1<sz(tl)&&tl[p1].fi.fi<pos)p1++;
		while(sz(q1)&&q1.top().fi<pos){
			pld t=q1.top();
			q1.pop();
			if(t.se==0)cnt--;
			if(t.se)p/=t.se;
			if(!cnt)p=1;
		}
		while(p1<sz(tl)&&tl[p1].fi.fi>=pos&&tl[p1].fi.se<=pos){
			p*=tl[p1].se;
			if(tl[p1].se==0)cnt++;
			q1.push(mp(tl[p1].fi.fi, tl[p1].se));
			p1++;
		}
		ans+=mush[p2].se*p;
	}
	printf("%.10f\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
const int N=1e5+10;
int n, m;
typedef pair<ll, double>  pld;
typedef pair<ll, ll> pll;
vector<pair<pll, ll> > tl, tr;
vector<pii> mush;
priority_queue<pld, vector<pld>, greater<pld> > q1;
double ans;
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 0, n){
		int a, h, l, r;
		scanf("%d%d%d%d", &a, &h, &l, &r);
		tl.pb(mp(mp((0LL+a-1), (0LL+a-h)), 100-l));
		tl.pb(mp(mp((0LL+a+h), (0LL+a+1)), 100-r));
	}
	rep(i, 0, m){
		int b, z;
		scanf("%d%d", &b, &z);
		mush.pb(mp(b, z));
	}
	sort(tl.begin(), tl.end());
	sort(mush.begin(), mush.end());
	int p1, p2;
	double p=0;
	int cnt=0;
	for(p1=0, p2=0; p2<m; p2++){
		ll pos=mush[p2].fi;
		while(sz(q1)&&q1.top().fi<pos){
			pld t=q1.top();
			q1.pop();
			if(t.se==0)cnt--;
			if(t.se)p-=log(t.se)-log(100);
		}
		while(p1<sz(tl)&&tl[p1].fi.fi<pos)p1++;

		while(p1<sz(tl)&&tl[p1].fi.fi>=pos&&tl[p1].fi.se<=pos){
			if(tl[p1].se==0)cnt++;
			else p+=log(tl[p1].se)-log(100);
			q1.push(mp(tl[p1].fi.fi, tl[p1].se));
			p1++;
		}
		if(!cnt)ans+=mush[p2].se*exp(p);
	}
	printf("%.10f\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
const int N=1e5+10;
int n, m;
typedef pair<ll, double>  pld;
typedef pair<ll, ll> pll;
vector<pair<pll, double> > tl, tr;
vector<pii> mush;
priority_queue<pld, vector<pld>, greater<pld> > q1;
double ans;
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 0, n){
		int a, h, l, r;
		scanf("%d%d%d%d", &a, &h, &l, &r);
		tl.pb(mp(mp((0LL+a-1), (0LL+a-h)), 1.*(100-l)/100));
		tl.pb(mp(mp((0LL+a+h), (0LL+a+1)), 1.*(100-r)/100));
	}
	rep(i, 0, m){
		int b, z;
		scanf("%d%d", &b, &z);
		mush.pb(mp(b, z));
	}
	sort(tl.begin(), tl.end());
	sort(mush.begin(), mush.end());
	int p1, p2;
	double p=1;
	int cnt=0;
	for(p1=0, p2=0; p2<m; p2++){
		ll pos=mush[p2].fi;
		while(sz(q1)&&q1.top().fi<pos){
			pld t=q1.top();
			q1.pop();
			if(t.se==0)cnt--;
			if(t.se)p/=t.se;
			if(!cnt)p=1;
		}
		while(p1<sz(tl)&&tl[p1].fi.fi<pos)p1++;
		while(p1<sz(tl)&&tl[p1].fi.fi>=pos&&tl[p1].fi.se<=pos){
			p*=tl[p1].se;
			if(tl[p1].se==0)cnt++;
			q1.push(mp(tl[p1].fi.fi, tl[p1].se));
			p1++;
		}
		ans+=mush[p2].se*p;
	}
	printf("%.10f\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
const int N=1e5+10;
int n, m;
typedef pair<ll, double>  pld;
typedef pair<ll, ll> pll;
vector<pair<pll, ll> > tl, tr;
vector<pii> mush;
priority_queue<pll, vector<pll>, greater<pll> > q1;
double ans;
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 0, n){
		int a, h, l, r;
		scanf("%d%d%d%d", &a, &h, &l, &r);
		tl.pb(mp(mp((0LL+a-1), (0LL+a-h)), 100-l));
		tl.pb(mp(mp((0LL+a+h), (0LL+a+1)), 100-r));
	}
	rep(i, 0, m){
		int b, z;
		scanf("%d%d", &b, &z);
		mush.pb(mp(b, z));
	}
	sort(tl.begin(), tl.end());
	sort(mush.begin(), mush.end());
	int p1, p2;
	double p=0;
	int cnt=0;
	for(p1=0, p2=0; p2<m; p2++){
		ll pos=mush[p2].fi;
		while(sz(q1)&&q1.top().fi<pos){
			pld t=q1.top();
			q1.pop();
			if(t.se==0)cnt--;
			if(t.se)p-=log(t.se)-log(100);
		}
		while(p1<sz(tl)&&tl[p1].fi.fi<pos)p1++;

		while(p1<sz(tl)&&tl[p1].fi.fi>=pos&&tl[p1].fi.se<=pos){
			if(tl[p1].se==0)cnt++;
			else p+=log(tl[p1].se)-log(100);
			q1.push(mp(tl[p1].fi.fi, tl[p1].se));
			p1++;
		}
		if(!cnt)ans+=mush[p2].se*exp(p);
	}
	printf("%.10f\n", ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) (int)a.size()
#define rep(i, a, b) for(int i=(a); i<(b); i++)
//-----
const int N=1e5+10;
int n, m;
typedef pair<ll, double>  pld;
typedef pair<ll, ll> pll;
vector<pair<pll, ll> > tl, tr;
vector<pii> mush;
priority_queue<pll, vector<pll>, greater<pll> > q1;
priority_queue<pll, vector<pll>, greater<pll> > q2;
double ans;
int main() {
	scanf("%d%d", &n, &m);
	rep(i, 0, n){
		int a, h, l, r;
		scanf("%d%d%d%d", &a, &h, &l, &r);
		tl.pb(mp(mp((0LL+a-h), (0LL+a-1)), 100-l));
		tl.pb(mp(mp((0LL+a+1), (0LL+a+h)), 100-r));
	}
	rep(i, 0, m){
		int b, z;
		scanf("%d%d", &b, &z);
		mush.pb(mp(b, z));
	}
	sort(tl.begin(), tl.end());
	sort(mush.begin(), mush.end());
	int p1, p2;
	double p=0;
	int cnt=0;
	for(p1=0, p2=0; p2<m; p2++){
		ll pos=mush[p2].fi;
		while(sz(q1)&&q1.top().fi<pos){
			pld t=q1.top();
			q1.pop();
			if(t.se==0)cnt--;
			if(t.se)p-=log(t.se)-log(100);
		}
		while(p1<sz(tl)&&tl[p1].fi.fi<=pos){
			if(tl[p1].fi.se>=pos){
				if(tl[p1].se==0)
					cnt++;
				else{
					p+=log(tl[p1].se)-log(100);
					q1.push(mp(tl[p1].fi.se, tl[p1].se));
				}
			}
			p1++;
		}
		if(!cnt)ans+=mush[p2].se*exp(p);
	}
	printf("%.10f\n", ans);
	return 0;
}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define fi(ss) freopen (ss,"r",stdin)
#define fo(ss) freopen (ss,"w",stdout)
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
#define lp(i,n) for(int i = 0 ; i < n ; ++i)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;
vector<pii> mushrom;
vector<pii> tree;
const int maxn = 100005;
double l[maxn],r[maxn],s[maxn];
int n,m;
int z[maxn];
double p[maxn];
int main() {
	ios
	cout << fixed;
	cout << setprecision(6);
	cin >> n >> m;
	for(int i = 0 ; i < n ; ++i) {
		int a,h;
		cin >> a >> h;
		tree.pb(pii(a,h));
		cin >> l[i] >> r[i];
		s[i] = 100 - (l[i] + r[i]);
		s[i] /= 100.0;
		l[i] /= 100.0, r[i] /= 100.0;
	}
	for(int i = 0 ; i < maxn ; ++i) p[i] = 1.0;
	for(int j = 0 ; j < m ; ++j) {
		int a,z;
		cin >> a >> z;
		mushrom.pb(pii(a,z));
	}
	mushrom.pb(pii(1 << 30,1 << 30));
	sort(all(mushrom));

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

		// does not hit left

		double prob = s[i] + r[i];

		vector<pii>::iterator it1 = lower_bound(all(mushrom),pii(tree[i].first - tree[i].second,-1));
		vector<pii>::iterator it2 = lower_bound(all(mushrom),pii(tree[i].first,-1));
		if(prob == 0.0) {
			z[it1 - mushrom.begin()]++;
			z[it2 - mushrom.begin()]--;
		} else {
			p[it1 - mushrom.begin()] *= prob;
			p[it2 - mushrom.begin()] /= prob;
		}

		// does not hit right
		prob = s[i] + l[i];

		it1  = lower_bound(all(mushrom),pii(tree[i].first + 1,-1));
		it2 = lower_bound(all(mushrom),pii(tree[i].first + tree[i].second + 1,-1));
		if(prob == 0.0) {
			z[it1 - mushrom.begin()]++;
			z[it2 - mushrom.begin()]--;
		} else {
			p[it1 - mushrom.begin()] *= prob;
			p[it2 - mushrom.begin()] /= prob;
		}

	}
	for(int i = 1 ; i < m ; ++i) p[i] *= p[i - 1],z[i] += z[i - 1];
	double s = 0.0;
	for (int i = 0 ; i < m ; ++i) {
		//cout << "coefs " << p[i] << "\n";
		if(z[i] == 0)
		s += 1.0*p[i] * mushrom[i].second;
	}
	cout << s << "\n";

}


#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<string>
#include<vector>
#include<numeric>
#include <unordered_map>
using namespace std;
#define ll  long long
#define pb push_back
#define fi(ss) freopen (ss,"r",stdin)
#define fo(ss) freopen (ss,"w",stdout)
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
#define lp(i,n) for(int i = 0 ; i < n ; ++i)
typedef pair<int,int> pii;
#define ios std::ios_base::sync_with_stdio(false);
using namespace std;
vector<pii> mushrom;
vector<pii> tree;
const int maxn = 100005;
double l[maxn],r[maxn],s[maxn];
int n,m;
double p[maxn];
int main() {
	ios
	cout << fixed;
	cout << setprecision(6);
	cin >> n >> m;
	for(int i = 0 ; i < n ; ++i) {
		int a,h;
		cin >> a >> h;
		tree.pb(pii(a,h));
		cin >> l[i] >> r[i];
		s[i] = 100 - (l[i] + r[i]);
		s[i] /= 100.0;
		l[i] /= 100.0, r[i] /= 100.0;
	}
	for(int i = 0 ; i < maxn ; ++i) p[i] = 1.0;
	for(int j = 0 ; j < m ; ++j) {
		int a,z;
		cin >> a >> z;
		mushrom.pb(pii(a,z));
	}
	mushrom.pb(pii(1 << 30,1 << 30));
	sort(all(mushrom));

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

		// does not hit left
		double prob = s[i] + r[i];
		vector<pii>::iterator it1 = lower_bound(all(mushrom),pii(tree[i].first - tree[i].second,-1));
		vector<pii>::iterator it2 = lower_bound(all(mushrom),pii(tree[i].first,-1));
		p[it1 - mushrom.begin()] *= prob;
		p[it2 - mushrom.begin()] /= prob;
		// does not hit right
		prob = s[i] + l[i];
		it1 = lower_bound(all(mushrom),pii(tree[i].first + 1,-1));
		it2 = lower_bound(all(mushrom),pii(tree[i].first + tree[i].second + 1,-1));
		p[it1 - mushrom.begin()] *= prob;
		p[it2 - mushrom.begin()] /= prob;
	}
	for(int i = 1 ; i < m ; ++i) p[i] *= p[i - 1];
	double s = 0.0;
	for (int i = 0 ; i < m ; ++i) {
		s += 1.0*p[i] * mushrom[i].second;
	}
	cout << s << "\n";

}


#include <bits/stdc++.h>

using namespace std;

#define fin cin
#define fout cout
//ifstream fin("x.in"); ofstream fout("x.out");

typedef long long i64;

const i64 inf = 2e9 + 1;

struct Aint {
    double lazy;
    Aint *left, *right;

    Aint() {
        lazy = 1;
        left = right = 0;
    }
} *root;

void update (Aint* &nod, i64 x, i64 y, i64 st, i64 dr, double val) {
    if (st <= x && y <= dr) {
        nod -> lazy *= val;
        return ;
    }

    i64 mij = (x + y) / 2;
    if (st <= mij) {
        if (nod -> left == 0)
            nod -> left = new Aint();
        update(nod -> left, x, mij, st, dr, val);
    }
    if (mij < dr) {
        if (nod -> right == 0)
            nod -> right = new Aint();
        update(nod -> right, mij + 1, y, st, dr, val);
    }
}

double query (Aint *nod, i64 x, i64 y, i64 pos) {
    if (x == y)
        return nod -> lazy;

    i64 mij = (x + y) / 2;
    double ans = 1;

    if (pos <= mij) {
        if (nod -> left != 0)
            ans = query(nod -> left, x, mij, pos);
    } else {
        if (nod -> right != 0)
            ans = query(nod -> right, mij + 1, y, pos);
    }
    return nod -> lazy * ans;
}

int main() {
    fin.sync_with_stdio(false);
    fin.tie();
    fout.tie();

    int n, m;
    fin >> n >> m;

    root = new Aint();

    for (int i = 1; i <= n; ++ i) {
        i64 x, h, l, r;
        fin >> x >> h >> l >> r;

        x += inf;
        update(root, 1, inf + inf, x - h, x - 1, 1.0 * (100 - l) / 100);
        update(root, 1, inf + inf, x + 1, x + h, 1.0 * (100 - r) / 100);
    }

    double ans = 0;
    for (int i = 1; i <= m; ++ i) {
        i64 x, y;
        fin >> x >> y;

        x += inf;
        ans += query(root, 1, inf + inf, x) * y;
    }
    fout << setprecision( 12 ) << fixed;
    fout << ans << "\n";
    return 0;
}


//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 1e6 + 5;
const double eps = 1e-9;
using namespace std;
int n, m;

struct arr
{
    int x, fl;
    double p;
};

arr a[MAXN];

int main()
{
    ni(n), ni(m);
    int k = 0;
    for (int i = 0; i < n; i++)
    {
        int x, h;
        double l, r;
        scanf("%d %d %lf %lf", &x, &h, &l, &r);
        if (l == 100)
            l -= 0.001;
        if (r == 100)
            r -= 0.001;
        a[k].x = x - h;
        a[k].p = log(1 - l / 100.);
        a[k++].fl = -1;

        a[k].x = x;
        a[k].p = -log(1 - l / 100.);
        a[k++].fl = -1;

        a[k].x = x;
        a[k].p = log(1 - r / 100.);
        a[k++].fl = 1;

        a[k].x = x + h;
        a[k].p = -log(1 - r / 100.);
        a[k++].fl = 1;
    }
    for (int i = 0;i < m; i++)
    {
        scanf("%d %lf", &a[k].x, &a[k].p);
        a[k++].fl = 0;
    }
    sort(a, a + k, [](arr lhs, arr rhs) -> bool
         {
            if (lhs.x == rhs.x)
                return lhs.fl < rhs.fl;
            return lhs.x < rhs.x;
         });
    double sum = 0, ans = 0;
    for (int i = 0; i < k; i++)
        if (a[i].fl)
            sum += a[i].p;
        else
            ans += a[i].p * exp(sum);
    printf("%.15f\n", ans);
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;

struct node{
	int x;
	bool tree;
	int full;
	double p;

	bool operator<(const node &n) const{
		if (x == n.x) return tree;
		return x < n.x;
	}
};

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

	int n, m;
	cin >> n >> m;
	vector<node> events;
	for (int i = 0; i < n; ++i){
		int x, h, l, r;
		cin >> x >> h >> l >> r;
		if (l < 100){
			double prob = log(1.0 - 1.0 * l / 100);
			events.push_back({x - h, true, 00, prob});
			events.push_back({x, true, 0, -prob});
		}
		else{
			events.push_back({x - h, true, 1, 0});
			events.push_back({x, true, -1, -0});
		}

		if (r < 100){
			double prob = log(1.0 - 1.0 * r / 100);
			events.push_back({x + 1, true, 0, prob});
			events.push_back({x + h + 1, true, 0, -prob});
		}
		else{
			events.push_back({x + 1, true, 1, 0});
			events.push_back({x + h + 1, true, -1, -0});
		}
	}

	for (int i = 0; i < m; ++i){
		int x, p;
		cin >> x >> p;
		events.push_back({x, false, 0, (double)p});
	}

	sort(events.begin(), events.end());

	int tot = 0;
	double p = 0;
	double ans = 0;

	for (auto e : events){
		tot += e.full;
		if (e.tree){
			p += e.p;
		}
		else{
			if (!tot)
				ans += exp(p) * e.p;
		}
	}

	cout.precision(10);
	cout << fixed << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;

struct node{
	int x;
	bool tree;
	int full;
	ld p;

	bool operator<(const node &n) const{
		if (x == n.x) return tree;
		return x < n.x;
	}
};

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

	int n, m;
	cin >> n >> m;
	vector<node> events;
	for (int i = 0; i < n; ++i){
		int x, h, l, r;
		cin >> x >> h >> l >> r;
		if (l < 100){
			ld prob = log(1.0 * (100 - l) / 100.0);
			events.push_back({x - h, true, 0, prob});
			events.push_back({x, true, 0, -prob});
		}
		else{
			events.push_back({x - h, true, 1, 0});
			events.push_back({x, true, -1, -0});
		}

		if (r < 100){
			ld prob = log(1.0 * (100 - r) / 100.0);
			events.push_back({x + 1, true, 0, prob});
			events.push_back({x + h + 1, true, 0, -prob});
		}
		else{
			events.push_back({x + 1, true, 1, 0});
			events.push_back({x + h + 1, true, -1, -0});
		}
	}

	for (int i = 0; i < m; ++i){
		int x, p;
		cin >> x >> p;
		events.push_back({x, false, 0, (ld)p});
	}

	sort(events.begin(), events.end());

	int tot = 0;
	ld p = 0;
	ld ans = 0;

	for (auto e : events){
		tot += e.full;
		if (e.tree){
			p += e.p;
		}
		else{
			if (!tot)
				ans += exp(p) * e.p;
		}
	}

	cout.precision(10);
	cout << fixed << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;

struct node{
	int x;
	bool tree;
	int full;
	ld p;

	bool operator<(const node &n) const{
		if (x == n.x) return tree;
		return x < n.x;
	}
};

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

	int n, m;
	cin >> n >> m;
	vector<node> events;
	for (int i = 0; i < n; ++i){
		int x, h, l, r;
		cin >> x >> h >> l >> r;
		if (l < 100){
			ld v = 100 - l;
			ld prob = log(v / 100.0);
			events.push_back({x - h, true, 0, prob});
			events.push_back({x, true, 0, -prob});
		}
		else{
			events.push_back({x - h, true, 1, 0});
			events.push_back({x, true, -1, -0});
		}

		if (r < 100){
			ld v = 100 - r;
			ld prob = log(v / 100.0);
			events.push_back({x + 1, true, 0, prob});
			events.push_back({x + h + 1, true, 0, -prob});
		}
		else{
			events.push_back({x + 1, true, 1, 0});
			events.push_back({x + h + 1, true, -1, -0});
		}
	}

	for (int i = 0; i < m; ++i){
		int x, p;
		cin >> x >> p;
		events.push_back({x, false, 0, (ld)p});
	}

	sort(events.begin(), events.end());

	int tot = 0;
	ld p = 0;
	ld ans = 0;

	for (auto e : events){
		tot += e.full;
		if (e.tree){
			p += e.p;
		}
		else{
			if (!tot)
				ans += exp(p) * e.p;
		}
	}

	cout.precision(10);
	cout << fixed << ans << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int64;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long double ld;

struct node{
	int x;
	int mode;
	int p;

	bool operator<(const node &n) const{
		if (x == n.x) return abs(mode) > abs(n.mode);
		return x < n.x;
	}
};

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

	int n, m;
	cin >> n >> m;
	vector<node> events;
	for (int i = 0; i < n; ++i){
		int x, h, l, r;
		cin >> x >> h >> l >> r;

		events.push_back({x - h, 1, (100 - l)});
		events.push_back({x, -1, (100 - l)});
		events.push_back({x + 1, 1, (100 - r)});
		events.push_back({x + h + 1, -1, (100 - r)});
	}

	for (int i = 0; i < m; ++i){
		int x, p;
		cin >> x >> p;
		events.push_back({x, 0, p});
	}

	sort(events.begin(), events.end());

	int tot = 0;
	ld p = 0;
	ld ans = 0;

	for (auto e : events){
		if (e.mode == 1){
			if (e.p == 0) tot++;
			else p += log(e.p / 100.0);
		}
		else if (e.mode == -1){
			if (e.p == 0) tot--;
			else p -= log(e.p / 100.0);
		}
		else{
			if (tot == 0) ans += exp(p) * e.p;
		}
	}

	cout.precision(10);
	cout << fixed << ans << endl;

	return 0;
}


#include <iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define inf 1000000000000
#define mod 1000000009
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define S second
#define F first
#define boost ios::sync_with_stdio(false);

ll a[1000001],b[1000001],h[1000001];
double l[1000001],r[1000001],tree[4000001],z[1000001];
map<ll,ll>assign;
vector<ll>v;

void build(ll node,ll a,ll b)
{
	tree[node]=1.0;
	if(a!=b)
	{
		ll mid=(a+b)/2;
		build(2*node,a,mid);
		build(2*node+1,mid+1,b);
	}
}
void update(ll node,ll a,ll b,ll l,ll r,double val)
{
	if(a>b || a>r || b<l)
	return;
	if(a>=l && b<=r)
	{
		tree[node]*=val;
		return;
	}
	ll mid=(a+b)/2;
	if(a!=b){
	update(2*node,a,mid,l,r,val);
	update(2*node+1,mid+1,b,l,r,val);}
}
double query(ll node,ll a,ll b,ll l,ll r)
{
	if(a>b || a>r || b<l)
	return 1.0;
	if(a>=l && b<=r)
	return tree[node];
	ll mid=(a+b)/2;
	return tree[node]*query(2*node,a,mid,l,r)*query(2*node+1,mid+1,b,l,r);
}
int main()
{
	boost;
	cout<<fixed<<setprecision(10);
	ll i,j,n,m,x,y,size;
	double ans=0.0;
	cin>>n>>m;
	for(i=1;i<=n;i++)
	{
		cin>>a[i]>>h[i]>>l[i]>>r[i];
		v.pb(a[i]-1);
		v.pb(a[i]+1);
		v.pb(a[i]+h[i]);
		v.pb(a[i]-h[i]);
		l[i]/=100.0;;
		r[i]/=100.0;
	}
	for(i=1;i<=m;i++)
	{
		cin>>b[i]>>z[i];
		v.pb(b[i]);
	}
	sort(all(v));
	for(i=0;i<v.size();i++)
	assign[v[i]]=i+1;
	size=v.size();
	size++;
	build(1,1,size);
	for(i=1;i<=n;i++)
	{
		update(1,1,size,assign[a[i]+1],assign[a[i]+h[i]],1-r[i]);
		update(1,1,size,assign[a[i]-h[i]],assign[a[i]-1],1-l[i]);
	}
	for(i=1;i<=m;i++)
	ans+=query(1,1,size,assign[b[i]],assign[b[i]])*z[i];
	cout<<ans;
	return 0;
}