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

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

j = A("j")
b = B("b")
h = B("h")
a = A("a")

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

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

j = A("j")
b = B("b")
h = B("h")
a = A("a")

j.w = a
j.r = a
b.x = h
h.x = b
a.w = j
a.r = j
assert h.x.x.x.x.txt == "h"