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

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

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

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

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

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

k.z = f
m.v = e
m.x = f
f.z = k
e.v = m
e.x = k
assert m.x.z.z.txt == "f"