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

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

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

n = A("n")
m = B("m")
c = C("c")
k = A("k")

n.y = c
n.q = c
n.p = m
m.s = k
c.o = n
c.q = m
k.y = c
k.q = c
k.p = m
assert n.y.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.p: B = None
        self.q: C = None
        self.txt = txt

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

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

n = A("n")
m = B("m")
c = C("c")
k = A("k")

n.y = c
n.q = c
n.p = m
m.s = k
c.o = n
c.q = m
k.y = c
k.q = c
k.p = m
assert n.y.q.s.txt == "k"