There are a few steps you will need to take to set this up.
First on the first page of Shipping Settings add in a $3 handling fee and make sure that the Weight Unit Preference is set to grams, then click Next.
I will use your example for country A above.
Use the shipping rate calculator drop down to choose Flat. Enter in your flat rate as $7, select the country and click Submit.
Now create a new rule identical to the above rule except place a minimum weight of 501 grams. Repeat this for 1001, 1501, etc. This way when a buyer checks out with 100 grams they will be charged $10, if the total weight is 700 grams it will be $17
You can repeat this country B except replace the $7 flat amount with $5 and change the country selected in the rules.
If you are in the US you can us one of the USPS shipping methods as the rates buyers get for those methods are calculated by the USPS servers.