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

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

g = A("g")
d = B("d")
m = A("m")
f = A("f")
h = B("h")

g.z = f
g.u = h
d.u = g
m.z = g
m.u = h
f.z = m
f.u = h
h.u = f
assert f.u.u.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.u: B = None
        self.txt = txt

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

g = A("g")
d = B("d")
m = A("m")
f = A("f")
h = B("h")

g.z = f
g.u = h
d.u = g
m.z = g
m.u = h
f.z = m
f.u = h
h.u = f
assert f.u.u.z.z.txt == "g"