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

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

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

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

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

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

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