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

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

f = A("f")
c = B("c")
d = A("d")
m = A("m")
e = B("e")
a = A("a")

f.y = m
f.z = e
c.t = f
d.y = a
d.z = c
m.y = f
m.z = e
e.t = d
a.y = f
a.z = e
assert a.z.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: B = None
        self.txt = txt

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

f = A("f")
c = B("c")
d = A("d")
m = A("m")
e = B("e")
a = A("a")

f.y = m
f.z = e
c.t = f
d.y = a
d.z = c
m.y = f
m.z = e
e.t = d
a.y = f
a.z = e
assert a.z.t.z.txt == "c"