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

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

j = A("j")
m = B("m")
l = A("l")
e = A("e")

j.r = m
j.x = l
m.w = l
l.r = m
l.x = e
e.r = m
e.x = l
assert j.r.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.x: A = None
        self.txt = txt

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

j = A("j")
m = B("m")
l = A("l")
e = A("e")

j.r = m
j.x = l
m.w = l
l.r = m
l.x = e
e.r = m
e.x = l
assert j.r.w.r.txt == "m"