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

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

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

h = A("h")
n = B("n")
m = C("m")
c = C("c")
l = C("l")
f = B("f")

h.z = n
n.z = f
n.t = f
m.q = l
c.q = m
l.q = c
f.z = n
f.t = n
assert h.z.z.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

h = A("h")
n = B("n")
m = C("m")
c = C("c")
l = C("l")
f = B("f")

h.z = n
n.z = f
n.t = f
m.q = l
c.q = m
l.q = c
f.z = n
f.t = n
assert h.z.z.t.z.txt == "f"