class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.y: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

g = A("g")
i = B("i")
k = B("k")
l = B("l")
f = B("f")
n = A("n")

g.q = l
g.y = f
i.t = l
k.t = l
l.t = k
f.t = l
n.q = f
n.y = f
assert k.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.y: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

g = A("g")
i = B("i")
k = B("k")
l = B("l")
f = B("f")
n = A("n")

g.q = l
g.y = f
i.t = l
k.t = l
l.t = k
f.t = l
n.q = f
n.y = f
assert k.t.t.t.t.txt == "k"