Line 8: use W-2 box 1, minus $5000
Line 22: $5000.
Notice that you can not write the W-2 box 1 number on line 8 directly. Otherwise you may never subtract this $5000 since line 22 is only a declaration and is not involved in the calculation process.
I remember you still need to fill form 8833 or 8823.