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

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

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

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

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

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

i.r = d
l.r = i
l.q = d
d.r = i
d.q = l
assert i.r.q.q.txt == "d"