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

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

e = A("e")
h = B("h")
b = B("b")
i = B("i")
n = B("n")
g = A("g")
d = A("d")
a = B("a")
k = B("k")

e.p = n
h.u = e
b.u = g
i.u = d
n.u = d
g.p = k
d.p = b
a.u = e
k.u = d
assert a.u.p.u.p.u.p.u.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

e = A("e")
h = B("h")
b = B("b")
i = B("i")
n = B("n")
g = A("g")
d = A("d")
a = B("a")
k = B("k")

e.p = n
h.u = e
b.u = g
i.u = d
n.u = d
g.p = k
d.p = b
a.u = e
k.u = d
assert a.u.p.u.p.u.p.u.p.u.txt == "g"