You have several problems to solve each time the beam is reflected.
I like to use vectors to solve problems like these. All vectors in this problem have just two coordinates. You will need to know how to add two vectors, how to subtract one vector from another, how to take the scalar product of a number and a vector, and how to take the inner product (also call "dot product") of two vectors.
That is, if $u = (u_x, u_y)$ and $v = (v_x, v_y)$ are two vectors
and $r$ is a number,
\begin{align}
u + v &= (u_x + v_x, u_y + v_y), \\
u - v &= (u_x - v_x, u_y - v_y), \\
rv &= (rv_x, rv_y), \\
u \cdot v &= u_x v_x + u_y v_y.
\end{align}
Find where the beam of light might intersect a particular mirror
I assume you are given the starting point $p = (p_x,p_y)$ and a direction vector $v = (v_x, v_y)$ for the light ray. (Based on your input file and diagram, $p_x,p_y,v_x,v_y,$ in that order, appear to be the four numbers on the first line of the input.)
Construct another vector $w$ perpendicular to $v.$ One way to do that is to swap the $x$ and $y$ coordinates and then change the sign of one coordinate;
for example you can set $w = (-v_y,v_x).$
We will also treat positions as vectors. You can think of a "position vector" as the vector that gives the distance and direction from $(0,0)$ to a point, or you can just treat the coordinates of the point as if they were coordinates of a vector.
Given a mirror with endpoints at $a = (a_x,a_y)$ and $b = (b_x,b_y),$
construct the vectors that show the distance and direction from the starting point of the light ray to the endpoints of the mirrors.
These vectors are the vector differences $a - p$ and $b - p.$
Take the dot product of each of the last two vectors with the vector $w$:
\begin{align}
r_a &= (a - p) \cdot w, \\
r_b &= (b - p) \cdot w.
\end{align}
If the signs of $r_a$ and $r_b$ are the same (both positive or both negative), the light ray cannot intersect the mirror.
If the signs of $r_a$ and $r_b$ are opposite (one is positive, one is negative), then the light ray might reflect off the mirror.
There are several ways to try to find out if it actually does reflect,
but you might as well use the method that computes the possible point of intersection.
The reflection point, that is, the point where the light ray would hit the mirror (if it hits it at all) is at the position vector
$$
p' = \left(\frac{r_b}{r_b - r_a}\right) a
- \left(\frac{r_a}{r_b - r_a} \right) b.
$$
The distance and direction of $p'$ from $p$ is $p' - p.$
Take the dot product of this with the direction vector of the light ray:
$$
d = (p' - p) \cdot v.
$$
The number $d$ is a kind of measurement of the distance of the reflection point from the starting point of the light ray. If it is positive, the light ray is going toward the mirror; if negative, the light ray is going away from the mirror.
Determine which mirror the beam of light reflects from
For each mirror, follow the procedure to find where the beam of light would intersect it. Ignore the mirror if you find that $r_a$ and $r_b$ have the same sign or if $d$ is negative.
The mirror with the smallest positive value of $d$ is the one the light ray will reflect from.
Of course if you do not find any mirror with a positive value of $d,$
there is no reflection.
Construct the reflected beam of light
You now have a new starting point for the reflected light ray:
it is the position vector $p'$ where the incoming light ray intersected the mirror.
One way to find the direction of the reflected ray is as follows.
Given the mirror's endpoints, $a$ and $b,$ construct a vector $m= (m_x, m_y)$ that gives the direction and length of the mirror's surface:
$$
m = b - a.
$$
Construct a second vector $n = (n_x, n_y)$ perpendicular (normal) to the mirror:
$$
n = (-m_y, m_x).
$$
Take the dot product of each of these vectors with the vector $v,$
divided by the dot product of $m$ with itself; this gives you a number
by which you multiply each vector to obtain two new vectors, like this:
\begin{align}
m' &= \left(\frac{v \cdot m}{m\cdot m}\right) m, \\
n' &= \left(\frac{v \cdot n}{m\cdot m}\right) n.
\end{align}
(You can use $n\cdot n$ instead of $m\cdot m$ if you like; they are the same number.)
The vectors $m'$ and $n'$ are components of the vector $v$ parallel to the mirror and perpendicular to it.
That is, they add up to the original vector: $v = m' + n'.$
To get the direction of the reflected ray, you reverse the component of the light ray's direction that is perpendicular to the mirror: the new direction vector is
$$ v' = m' - n'.$$
Now you have a starting position $p'$ and a direction $v'$ of the reflected ray; repeat the procedure from the step "find where the beam of light might intersect a particular mirror" until there are no more reflections.
In the procedure above, I have tried to describe what each new position or vector is so that when you are debugging your program, you can check the steps one at a time to verify that they are producing the results they should. If there is a mistake in my explanation or an error in your implementation of it, you will be able to identify exactly which part of the algorithm was wrong.