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

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

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

g = A("g")
m = B("m")
a = C("a")
n = A("n")

g.p = n
g.x = a
g.t = m
m.q = a
a.s = m
n.p = g
n.x = a
n.t = m
assert a.s.q.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.x: C = None
        self.t: B = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
a = C("a")
n = A("n")

g.p = n
g.x = a
g.t = m
m.q = a
a.s = m
n.p = g
n.x = a
n.t = m
assert a.s.q.s.txt == "m"