Flank pain or the pain in the back just below the lower ribs to the left side of the trunk is usually due from either the kidney or the muscles in the area. Flank pain related to the kidneys can be caused by stones or infection. With regards to your right testicle pain, this could also be due to infection, inflammation of the structures in this area or possible hernia. If it persists, have this evaluated further by your doctor for proper management. Physical examination and some tests such as xray of the back or ultrasound may help. Direct clinical examination is important.
Take care and keep us posted.