##
**Problem:-**

You are conducting a contest at your college. This contest consists of two problems and participants. You know the problem that a candidate will solve during the contest.

You provide a balloon to a participant after he or she solves a problem. There are only green and purple-colored balloons available in a market. Each problem must have a balloon associated with it as a prize for solving that specific problem. You can distribute balloons to each participant by performing the following operation:

Input format

For each test case, print the minimum cost that you have to pay to purchase balloons.

You provide a balloon to a participant after he or she solves a problem. There are only green and purple-colored balloons available in a market. Each problem must have a balloon associated with it as a prize for solving that specific problem. You can distribute balloons to each participant by performing the following operation:

- Use green-colored balloons for the first problem and purple-colored balloons for the second problem
- Use purple-colored balloons for the first problem and green-colored balloons for the second problem

Input format

- First line: that denotes the number of test cases ()
- For each test case:
- First line: Cost of green and purple-colored balloons
- Second line: that denotes the number of participants ()

- Next lines: Contain the status of users. For example, if the value of the integer in the row is , then it depicts that the participant has not solved the problem. Similarly, if the value of the integer in the row is , then it depicts that the participant has solved the problem.

For each test case, print the minimum cost that you have to pay to purchase balloons.

SAMPLE INPUT

2 9 6 10 1 1 1 1 0 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 1 9 10 0 1 0 0 0 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0

SAMPLE OUTPUT

69## 14

##
**Solution:-**

**Here we take price of greeen ballooons in g and price of purple in p. For solving this**

**problem we first we give the green colour for first and purple colour for second question if student able to solve question i.e if input is 1 .and store total price in sum1 and then again we give the purple colour for first question and green colour for second question and store total price in sum2 .Then check which is minimum.After finding minimum print the min.**

#include<stdio.h>

int main()

{

int t,n,g,p,a[10][2],sum1,sum2,ans;

scanf("%d",&t);

for(int i=0;i<t;i++)

{

sum1=sum2=0;

scanf("%d%d",&g,&p);

scanf("%d",&n);

for(int j=0;j<n;j++)

{

for(int k=0;k<2;k++)

scanf("%d",&a[j][k]);

}

for(int j=0;j<n;j++)

{

if(a[j][0]==1)

sum1=sum1+g;

if(a[j][1]==1)

sum1=sum1+p;

}

for(int j=0;j<n;j++)

{

if(a[j][0]==1)

sum2=sum2+p;

if(a[j][1]==1)

sum2=sum2+g;

}

ans=sum1>sum2?sum2:sum1;

printf("%d\n",ans);

}

}