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

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

a = A("a")
h = B("h")
m = B("m")
j = B("j")
g = B("g")
e = A("e")

a.p = e
h.s = g
h.t = g
m.s = g
m.t = g
j.s = h
j.t = h
g.s = m
g.t = j
e.p = a
assert g.t.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

a = A("a")
h = B("h")
m = B("m")
j = B("j")
g = B("g")
e = A("e")

a.p = e
h.s = g
h.t = g
m.s = g
m.t = g
j.s = h
j.t = h
g.s = m
g.t = j
e.p = a
assert g.t.t.t.t.txt == "j"