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

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

e = A("e")
n = B("n")
j = A("j")
i = B("i")
c = B("c")
b = B("b")
m = A("m")
k = A("k")
d = A("d")
g = B("g")

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

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

e = A("e")
n = B("n")
j = A("j")
i = B("i")
c = B("c")
b = B("b")
m = A("m")
k = A("k")
d = A("d")
g = B("g")

e.u = c
n.p = d
j.u = b
i.p = e
c.p = j
b.p = d
m.u = n
k.u = c
d.u = g
g.p = e
assert g.p.u.p.u.p.txt == "d"