using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace cheap { class Scanner { TextReader Reader; public Scanner(TextReader reader) { Reader = reader; } static int Index = 0; static string[] CurrentLine = { }; public bool HasNext() { if (CurrentLine.Length == Index) { try { CurrentLine = Reader.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); Index = 0; return HasNext(); } catch (Exception e) { return false; } } return true; } public String Next() { if (HasNext()) return CurrentLine[Index++]; return null; } public int NextInt() { return int.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } public float NextFloat() { return float.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } } class CheapestBuy { static void Main(string[] args) { Scanner inp = new Scanner(Console.In); int cases = inp.NextInt(); for (int caseOn = 1; caseOn <= cases; caseOn++) { // number of Euros to the dollar double e = inp.NextDouble(); // number of Pounds to the dollar double p = inp.NextDouble(); int n = inp.NextInt(); double cost = 0; for (int i = 0; i < n; i++) { double usdcostEuro = inp.NextDouble() * e; double usdcostPound = inp.NextDouble() * p; if (usdcostEuro < usdcostPound) { cost += usdcostEuro; } else { cost += usdcostPound; } } Console.WriteLine("{0:F2}$", cost); } } } }