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

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

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

g = A("g")
d = B("d")
b = C("b")
m = C("m")
a = C("a")
c = B("c")
n = A("n")
k = B("k")

g.p = n
g.x = m
d.o = k
b.o = m
b.t = g
m.o = a
m.t = g
a.o = b
a.t = n
c.o = d
n.p = g
n.x = a
k.o = d
assert m.t.p.x.t.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.x: C = None
        self.txt = txt

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

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

g = A("g")
d = B("d")
b = C("b")
m = C("m")
a = C("a")
c = B("c")
n = A("n")
k = B("k")

g.p = n
g.x = m
d.o = k
b.o = m
b.t = g
m.o = a
m.t = g
a.o = b
a.t = n
c.o = d
n.p = g
n.x = a
k.o = d
assert m.t.p.x.t.p.p.p.txt == "g"