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

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

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

m.w = k
m.x = a
a.v = n
a.r = k
k.w = f
k.x = a
n.v = a
n.r = f
f.w = m
f.x = a
assert f.w.x.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.x: B = None
        self.txt = txt

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

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

m.w = k
m.x = a
a.v = n
a.r = k
k.w = f
k.x = a
n.v = a
n.r = f
f.w = m
f.x = a
assert f.w.x.v.v.txt == "a"