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

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

c = A("c")
n = B("n")
m = B("m")
a = B("a")
d = B("d")
g = B("g")
h = A("h")

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

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

c = A("c")
n = B("n")
m = B("m")
a = B("a")
d = B("d")
g = B("g")
h = A("h")

c.p = h
c.t = a
n.o = a
n.t = a
m.o = g
m.t = a
a.o = n
a.t = m
d.o = n
d.t = g
g.o = m
g.t = n
h.p = c
h.t = d
assert a.t.t.t.txt == "m"