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

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

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

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

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

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

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

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

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