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

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

e = A("e")
i = B("i")
j = A("j")
b = B("b")
g = A("g")
k = A("k")
h = A("h")

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

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

e = A("e")
i = B("i")
j = A("j")
b = B("b")
g = A("g")
k = A("k")
h = A("h")

e.u = h
e.p = g
i.w = b
j.u = g
j.p = k
b.w = i
g.u = j
g.p = h
k.u = g
k.p = h
h.u = g
h.p = g
assert h.p.p.u.p.u.p.txt == "h"