import java.lang.Math.*
import java.math.BigDecimal
import java.util.*

data class Point(val x:Double, val y:Double)
class Line private constructor (private val a:Double, private val b:Double, private val c:Double){ // ay = bx + c
    fun crossPoint(other:Line):Point?{
        return when{
            isPallarel(other) -> null
            else -> {
                val newy = (c * other.b - other.c * b) / (a * other.b - other.a * b) // ab'y - a'by = bb'x - bb'x + cb' - c'b
                val newx = (c * other.a - other.c * a) / (a * other.b - other.a * b) // aa'y - aa'y = a'bx - ab'x + ca' - c'a
                Point(newx, newy)
            }
        }
    }
    fun isPallarel(other:Line):Boolean {
        return a * other.b == b * other.a
    }
    fun x(y:Double):Double? {
        return when{
            isHorizontal() -> null
            else -> (a * y - c) / b
        }
    }
    fun x(y:Int):Double? = x(y.toDouble())
    fun y(x:Double):Double? {
        return when{
            isVertical() -> null
            else -> (b * x + c) / a
        }
    }
    fun y(x:Int):Double? = y(x.toDouble())
    fun isHorizontal():Boolean = b == 0e0
    fun isVertical():Boolean = a == 0e0
    companion object {
        fun lineOnTwoPoint(a:Point, b:Point):Line {
            return Line(a.x - b.x, a.y - b.y, b.y * (a.x - b.x) - b.x * (a.y - b.y))
        }
    }
}
data class Vector(val x:Double, val y:Double){
    fun cross(other:Vector):Double = x * other.y - y * other.x
    fun length():Double = sqrt(x * x + y * y)
    companion object {
        fun fromToPoint(from:Point, to:Point):Vector = Vector(to.x - from.x, to.y - from.y)
    }
}
data class Edge(val from:Point, val to:Point)
fun area(a:Point, b:Point):Double {
    return (a.y + b.y) * (a.x - b.x) / 2
}
fun Double.between(a:Double, b:Double):Boolean {
    return (a - this) * (b - this) <= 0
}
fun crossPoint(line:Line, edge:Edge):Point? {
    return line.crossPoint(Line.lineOnTwoPoint(edge.from, edge.to))?.let{
        when{
            it.x.between(edge.from.x, edge.to.x) && it.y.between(edge.from.y, edge.to.y) -> it
            else -> null
        }
    }
}
fun convexArea(points:Array<Point>):Double {
    if (points.size == 0) return 0e0
    var res:Double = 0.0
    for (i in 1 until points.size){
        res += area(points[i], points[i - 1])
    }
    return (res + area(points[0], points[points.size - 1])).let{if (it < 0) -it else it}
}
fun cutConvex(points:Array<Point>, from:Point, to:Point):Array<Point> {
    val line = Line.lineOnTwoPoint(from, to)
    val isLeft = Vector.fromToPoint(from, to).cross(Vector.fromToPoint(from, points[0])) > 0
    val crossPoints = points.indices.filter{i ->
        crossPoint(line, Edge(points[i], points[(i + 1) % points.size]))?.let{
            when {
                points[i].x == it.x && points[i].y == it.y -> null
                else -> it
            }
        } != null
    }
    if (crossPoints.size != 2) return points.filter{p -> Vector.fromToPoint(from, to).cross(Vector.fromToPoint(from, p)) >= 0}.toTypedArray()
    val (a, b) = crossPoints
    //println("${points[a]}, ${points[a + 1]}, ${crossPoint(line, Edge(points[a], points[a + 1]))}")
    //println("${points[b]}, ${points[(b + 1) % points.size]}, ${crossPoint(line, Edge(points[b], points[(b + 1) % points.size]))}")
    val res = LinkedList<Point>()
    if (isLeft){
        for (i in 0 .. a){
            res.push(points[i])
        }
        res.push(crossPoint(line, Edge(points[a], points[(a + 1) % points.size]))!!)
        res.push(crossPoint(line, Edge(points[b], points[(b + 1) % points.size]))!!)
        for (i in (b + 1) until points.size){
            res.push(points[i])
        }
    }else{
        res.push(crossPoint(line, Edge(points[a], points[(a + 1) % points.size]))!!)
        for (i in (a + 1) .. b){
            res.push(points[i])
        }
        res.push(crossPoint(line, Edge(points[b], points[(b + 1) % points.size]))!!)
    }
    return res.toTypedArray()
}
fun main(args:Array<String>):Unit{
    val n = readLine()!!.toInt()
    val points = Array(n){
        val (x, y) = readLine()!!.split(' ').map(String::toDouble)
        Point(x, y)
    }
    val q = readLine()!!.toInt()
    for (i in 0 until q){
        val (x1, y1, x2, y2) = readLine()!!.split(' ').map(String::toDouble)
        val cut = cutConvex(points, Point(x1, y1), Point(x2, y2))
        println(BigDecimal.valueOf(convexArea(cut)).toPlainString())
    }
}


Measured memory_bytes: 33004