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

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

b = A("b")
m = B("m")
h = B("h")
c = A("c")
j = B("j")

b.r = h
b.w = h
m.x = b
m.y = h
h.x = c
h.y = j
c.r = h
c.w = j
j.x = c
j.y = h
assert h.x.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.w: B = None
        self.txt = txt

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

b = A("b")
m = B("m")
h = B("h")
c = A("c")
j = B("j")

b.r = h
b.w = h
m.x = b
m.y = h
h.x = c
h.y = j
c.r = h
c.w = j
j.x = c
j.y = h
assert h.x.r.y.txt == "j"