First, the persons with speeds of 3 seconds and 1 second will cross the
bridge while holding the torch.
The 1 second person will stay on the other side of the bridge and 3
second person will come back with the torch.
Then the 8 and 12 second persons will cross the bridge.
Then the1 second person standing on the other side of the bridge will
carry the torch.
Then 1 second and 3 second person will cross the bridge.
The 1 second person will return and then will cross with the 6 seconds
They will finally to cross the bridge within the time limit.
First run 1 & 3 and 3 will return = 3+3 = 6 seconds
Second run 8 & 12 and 1 will return = 12+1 = 13 seconds
Third run 1 & 3 and 1 will return = 3 + 1 = 4 seconds
Fourth run 1 & 6 will cross the bridge = 6 seconds
No return as all have crossed the bridge
Total = 6 + 13 + 4 + 6 = 29