def cross_st(w0, w1)
  x00, y00, x01, y01 = w0
  x10, y10, x11, y11 = w1

  v0x, v0y = x01 - x00, y01 - y00
  v1x, v1y = x11 - x10, y11 - y10

  d = v0x * v1y - v0y * v1x
  return nil if d == 0

  px = x10 - x00
  py = y10 - y00

  s = (v1y * px - v1x * py).to_f / d
  t = (v0y * px - v0x * py).to_f / d

  return nil if s < 0.0 || s > 1.0 || t < 0.0 || t > 1.0

  [s * v0x + x00, s * v0y + y00, s, t]
end

def rev_deg(deg)
  deg <= 0 ? deg + 180 : deg - 180
end

def deg_change(deg0, deg1)
  d = deg1 - deg0
  while d < 0
    d += 360
  end
  while d > 360
    d -= 360
  end
  [d, 360 - d].min
end

### main

loop do
  n = gets.to_i
  break if n == 0

  wires = []
  n.times do
    x0, y0, x1, y1 = gets.split.map(&:to_i)
    deg = Math.atan2(y1 - y0, x1 - x0) * 180 / Math::PI
    wires << [x0, y0, x1, y1, deg, rev_deg(deg)]
  end
  #p wires

  sx, sy, gx, gy = gets.split.map(&:to_i)
  #p [sx, sy, gx, gy]

  nodes = [[], []]

  for i in (0...n)
    wi = wires[i]
    if sx == wi[0] && sy == wi[1]
      nodes[0] << [i, 0.0]
    elsif sx == wi[2] && sy == wi[3]
      nodes[0] << [i, 1.0]
    end
    if gx == wi[0] && gy == wi[1]
      nodes[1] << [i, 0.0]
    elsif gx == wi[2] && gy == wi[3]
      nodes[1] << [i, 1.0]
    end
  end
  
  for i in (0...(n - 1))
    wi = wires[i]
    for j in ((i + 1)...n)
      wj = wires[j]

      st = cross_st(wi, wj)
      if ! st.nil?
        x, y, s, t = st
        nodes << [[i, s], [j, t]]
      end
    end
  end
  #p nodes

  nnd = nodes.length

  edges = nnd.times.map{nnd.times.map{nil}}
  nbrs = nnd.times.map{[]}

  for k in (0...n)
    wins = []
    for i in (0...nnd)
      s = nodes[i].assoc(k)
      if ! s.nil?
        wins << [i, s[1]]
      end
    end

    nwins = wins.length
    deg0, deg1 = wires[k][4..5]

    for i in (0...(nwins - 1))
      i0, s0 = wins[i]
      for j in ((i + 1)...nwins)
        i1, s1 = wins[j]

        if s0 < s1
          edges[i0][i1] = deg0
          edges[i1][i0] = deg1
        else
          edges[i0][i1] = deg1
          edges[i1][i0] = deg0
        end

        nbrs[i0] << i1
        nbrs[i1] << i0
      end
    end
  end
  #p edges
  #p nbrs

  dists = nnd.times.map{nnd.times.map{Float::INFINITY}}
  q = []
  min_deg = Float::INFINITY
  
  for n1 in nbrs[0]
    dists[0][n1] = 0.0
    q << [0, n1]
  end

  while ! q.empty?
    u = q.min{|a, b| dists[a[0]][a[1]] <=> dists[b[0]][b[1]]}
    q.delete(u)

    u0, u1 = u
    du = dists[u0][u1]

    if u1 == 1
      min_deg = du if min_deg > du
      next
    end

    degu = edges[u0][u1]

    for v in nbrs[u1]
      degv = edges[u1][v]
      degc = deg_change(degu, degv)
      dv = dists[u1][v]
      if dv > du + degc
        dists[u1][v] = du + degc
        if dv == Float::INFINITY
          q << [u1, v]
        end
      end
    end
  end

  if min_deg == Float::INFINITY
    puts -1
  else
    puts "%.10f" % min_deg
  end
end