Upon seeing someone in trial or tribulation

Alhamdu lillāhi ‘l-ladhī `āfānī mimmab-talāka bihi wa faḍḍalanī `alā kathīrin mimman khalaqa tafḍīlā. Praise is to Allah Who has spared me what He has afflicted you with, and preferred me greatly above much of what He has created. Reference: At-Tirmidhi 5/493,4. See also Al-Albani, Sahih At-Tirmidhi 3/153.