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

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

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

m = A("m")
c = B("c")
k = C("k")
l = B("l")
g = C("g")
b = B("b")
f = C("f")

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

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

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

m = A("m")
c = B("c")
k = C("k")
l = B("l")
g = C("g")
b = B("b")
f = C("f")

m.q = k
c.s = b
c.y = g
k.p = l
l.s = c
l.y = g
g.p = l
b.s = c
b.y = k
f.p = c
assert g.p.y.p.y.p.s.y.txt == "g"