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

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

l = A("l")
c = B("c")
g = A("g")

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

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

l = A("l")
c = B("c")
g = A("g")

l.r = c
c.q = l
g.r = c
assert g.r.q.r.txt == "c"