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

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

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

i = A("i")
b = B("b")
a = C("a")
k = C("k")

i.p = k
i.q = b
b.r = i
a.r = k
k.r = a
assert i.p.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.q: B = None
        self.txt = txt

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

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

i = A("i")
b = B("b")
a = C("a")
k = C("k")

i.p = k
i.q = b
b.r = i
a.r = k
k.r = a
assert i.p.r.r.txt == "k"