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

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

c = A("c")
a = B("a")
b = A("b")
h = B("h")
n = B("n")
f = A("f")
k = A("k")

c.z = h
a.z = c
a.t = b
b.z = a
h.z = k
h.t = k
n.z = c
n.t = f
f.z = h
k.z = a
assert a.t.z.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

c = A("c")
a = B("a")
b = A("b")
h = B("h")
n = B("n")
f = A("f")
k = A("k")

c.z = h
a.z = c
a.t = b
b.z = a
h.z = k
h.t = k
n.z = c
n.t = f
f.z = h
k.z = a
assert a.t.z.t.txt == "b"