Two casks A and B were filled with two kinds of sherry. In cask A, the ratio of the two kinds of sherry is 2:7 while in B, it is 1:5. How many gallons will be taken from each cask to form a mixture which shall consist of 2 gal of one kind and 9 gal of the other?