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

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

m = A("m")
i = B("i")
b = A("b")
h = B("h")
n = A("n")

m.w = n
m.r = i
i.v = b
i.x = h
b.w = m
b.r = h
h.v = n
h.x = i
n.w = b
n.r = h
assert i.v.r.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.r: B = None
        self.txt = txt

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

m = A("m")
i = B("i")
b = A("b")
h = B("h")
n = A("n")

m.w = n
m.r = i
i.v = b
i.x = h
b.w = m
b.r = h
h.v = n
h.x = i
n.w = b
n.r = h
assert i.v.r.x.x.txt == "h"