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

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

i = A("i")
d = B("d")
g = B("g")
n = A("n")
h = B("h")
m = A("m")

i.t = d
d.q = g
g.q = d
n.t = g
h.q = d
m.t = h
assert n.t.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

i = A("i")
d = B("d")
g = B("g")
n = A("n")
h = B("h")
m = A("m")

i.t = d
d.q = g
g.q = d
n.t = g
h.q = d
m.t = h
assert n.t.q.q.q.txt == "d"