
class DisjointSet
  attr_accessor :parent, :rank

  def initialize
    @parent = {}
    @rank = {}
  end

  def make(node)
    @parent[node] = node
    @rank[node] = 0
  end

  def union(node1, node2)
    link(find(node1), find(node2))
  end

  def find(node)
    (@parent[node] == node) ? node : (@parent[node] = find(@parent[node]))
  end

  def link(node1, node2)
    if @rank[node1] < @rank[node2]
      @parent[node1] = node2
    else
      @parent[node2] = node1
      @rank[node1] += 1 if @rank[node1] == @rank[node2]
    end
  end
end

class Point
  attr_accessor :x, :y
  def initialize
    @x = 0; @y = 0
  end
  def initialize(x, y)
    @x = x; @y = y
  end
  def outer_product(p)
    p.x*@y-@x*p.y
  end
  def -(p)
    Point.new(@x - p.x, @y - p.y)
  end
end

class Quadrilateral
  attr_accessor :point
  def initialize
    @point = []
    4.times {@point.push(Point.new)}
  end
  def initialize(*points)
#     p points
    @point = []
    for i in 0...4
      @point[i] = Point.new(points[2*i], points[2*i + 1])
#       p @point[i].x
    end
  end
  def containPoint(p)
    edge = []
    for i in 0...4
      edge.push(Point.new(@point[(i+1)%4].x - @point[i].x, @point[(i+1)%4].y - @point[i].y))
    end
#     p edge
    plus = 0
    minus = 0
    for i in 0...4
      sign = edge[i].outer_product(p - @point[i])
      if sign == 0
        plus += 1
        minus += 1
      end
      plus += 1 if sign > 0
      minus += 1 if sign < 0
#     p sign
    end
#     p plus, minus
    (plus == 4) || (minus == 4)
  end
  def contain(quad)
    for i in 0...4
      return true if containPoint(quad.point[i])
    end
    false
  end
end

while true do
  n = gets.to_i
  break if n == 0
  n.times do
    m = gets.to_i
    quad = []
    m.times do
      quad.push(Quadrilateral.new(*gets.split.map(&:to_i)))
    end
    set = DisjointSet.new
    for i in 0...m
      set.make(quad[i])
      for j in 0...i
        set.union(quad[i], quad[j]) if quad[i].contain(quad[j])
        set.union(quad[i], quad[j]) if quad[j].contain(quad[i])
      end
    end
    root = {}
    for i in 0...m
      root.store(set.find(quad[i]), 1)
    end
    puts root.size
  end
end