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

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

c = A("c")
i = B("i")
b = B("b")
d = A("d")
l = B("l")

c.x = d
c.r = i
i.s = b
i.r = d
b.s = i
b.r = d
d.x = c
d.r = i
l.s = i
l.r = d
assert d.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.r: B = None
        self.txt = txt

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

c = A("c")
i = B("i")
b = B("b")
d = A("d")
l = B("l")

c.x = d
c.r = i
i.s = b
i.r = d
b.s = i
b.r = d
d.x = c
d.r = i
l.s = i
l.r = d
assert d.r.r.r.txt == "i"