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

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

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

c = A("c")
b = B("b")
l = C("l")

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

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

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

c = A("c")
b = B("b")
l = C("l")

c.q = l
b.q = c
b.y = c
l.r = b
assert c.q.r.q.txt == "c"