Let the initial quantity of grains be $x$. The first customer buys half of $x$ plus 3 kg, leaving $\frac{x}{2} - 3$ kg. The second customer then buys half of the remaining grains plus 3 kg, leaving $\frac{x}{4} - 3$ kg. The third customer buys half of what is left plus 3 kg, leaving 0 grains. Thus, we have the equation:
$\frac{x}{8} - 3 = 0 \implies x = 42$