Two jugs each have a capacity of x gallons. One is filled with wine and the other is filled with water. Two gallons are taken from each jug and are then transferred into the other, after which each jug has its contents thoroughly mixed. If two gallons were now taken from each jug and then transferred into the other, the amount of wine in each jug would be the same. Find x.