Germany: Must beat Costa Rica to have a chance, and a win by eight goals secures the top 2 in all scenarios.
If Germany and Spain win, Germany finish second.
If Germany win and Spain lose, Germany would have to overturn a goal-difference deficit of eight goals, as noted in the Spain section.
If Germany win and Japan-Spain is a draw, Germany can qualify as noted in the Japan section.