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

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

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

i = A("i")
a = B("a")
c = C("c")
g = B("g")

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

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

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

i = A("i")
a = B("a")
c = C("c")
g = B("g")

i.w = c
i.s = c
i.q = c
a.p = g
a.r = c
c.r = i
c.p = i
c.z = a
g.p = a
g.r = c
assert g.r.r.s.txt == "c"