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

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

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

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

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

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

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

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

g.p = k
g.s = b
g.r = b
b.x = k
k.q = g
i.q = g
assert i.q.p.q.r.txt == "b"