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

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

b = A("b")
a = B("a")
e = A("e")
h = A("h")
c = B("c")
f = B("f")

b.y = a
a.u = c
a.z = h
e.y = f
h.y = f
c.u = f
c.z = e
f.u = c
f.z = e
assert f.u.z.y.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

b = A("b")
a = B("a")
e = A("e")
h = A("h")
c = B("c")
f = B("f")

b.y = a
a.u = c
a.z = h
e.y = f
h.y = f
c.u = f
c.z = e
f.u = c
f.z = e
assert f.u.z.y.u.z.txt == "e"