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

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

g = A("g")
c = B("c")
n = B("n")
a = A("a")
d = B("d")
i = A("i")
j = A("j")
l = A("l")
m = A("m")

g.x = a
g.p = d
c.t = i
n.t = a
a.x = g
a.p = n
d.t = m
i.x = m
i.p = d
j.x = a
j.p = c
l.x = j
l.p = d
m.x = g
m.p = c
assert n.t.x.p.t.x.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: B = None
        self.txt = txt

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

g = A("g")
c = B("c")
n = B("n")
a = A("a")
d = B("d")
i = A("i")
j = A("j")
l = A("l")
m = A("m")

g.x = a
g.p = d
c.t = i
n.t = a
a.x = g
a.p = n
d.t = m
i.x = m
i.p = d
j.x = a
j.p = c
l.x = j
l.p = d
m.x = g
m.p = c
assert n.t.x.p.t.x.p.t.txt == "m"