concatenating specific rows together

Hello community,

I am trying to concatenate row together but i am finding some diffuculty. I tried a loop but i am missin somtheting. below is a sample data

| id | flag | message          | indexing |
| c1 | a    | ggg              | 1        |
| c1 |      | hello            | 1        |
| c1 |      | done             | 1        |
| c1 | b    | text tetx        | 2        |
| c1 |      | answer           | 2        |
| c1 | C    | questionquestion | 3        |
| c1 |      | answer           | 3        |
| c1 |      | b                | 3        |
| c1 |      | v                | 3        |
| c1 |      | c                | 3        |
| c2 | a    | text3            | 4        |
| c2 |      | text4            | 4        |
| c2 |      | tex5             | 4        |
| c2 | b    | tex6             | 5        |
| c2 |      | tex7             | 5        |

i need 1st to give an index as previwed above then i need to concatenate all rows that are under a certain flag. when the flag is not empty, it means a question, and when it is empty it means asnswers for that question. so i need to group the answers together.

if anybody can help i would rreally appreciate