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

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

l = A("l")
f = B("f")
a = B("a")
j = A("j")

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

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

l = A("l")
f = B("f")
a = B("a")
j = A("j")

l.x = j
f.w = a
f.r = a
a.w = f
a.r = f
j.x = l
assert j.x.x.x.x.txt == "j"