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

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

k = A("k")
h = B("h")
m = B("m")
f = A("f")
j = B("j")
e = B("e")

k.v = e
h.u = f
h.z = e
m.u = k
m.z = h
f.v = j
j.u = f
j.z = h
e.u = k
e.z = h
assert m.z.u.v.z.u.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

k = A("k")
h = B("h")
m = B("m")
f = A("f")
j = B("j")
e = B("e")

k.v = e
h.u = f
h.z = e
m.u = k
m.z = h
f.v = j
j.u = f
j.z = h
e.u = k
e.z = h
assert m.z.u.v.z.u.v.txt == "j"