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

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

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

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

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

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

n.v = k
n.z = f
k.v = f
k.y = n
m.v = f
m.y = f
f.v = m
f.z = n
assert m.v.z.v.txt == "k"