From Walmart, you have to buy at-least= 50/8 = 6.25 = 7 [round-off to larger direction value ]
So, it would cost = 7 * 2.99 = $20.93
From Sam's club, you have to buy at-least= 50/12 = 4.16 = 5 [round-off to larger direction value ]
So, it would cost = 5 * 3.19 = $15.95
In short, Sam's club offers the better deal.
Now, we can spend our minimum expense, by buying 3 pcs. of bun from Sam's club and 2 from walmart.
In that case, it would cost = 3*3.19 + 2*2.99 = $15.55
Hope this helps!