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

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

g = A("g")
i = B("i")
f = A("f")
b = B("b")
h = A("h")
e = A("e")
l = B("l")
d = A("d")
c = A("c")

g.u = c
g.p = i
i.w = f
f.u = h
f.p = l
b.w = d
h.u = f
h.p = i
e.u = d
e.p = l
l.w = f
d.u = c
d.p = l
c.u = d
c.p = b
assert e.p.w.p.w.u.p.w.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.p: B = None
        self.txt = txt

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

g = A("g")
i = B("i")
f = A("f")
b = B("b")
h = A("h")
e = A("e")
l = B("l")
d = A("d")
c = A("c")

g.u = c
g.p = i
i.w = f
f.u = h
f.p = l
b.w = d
h.u = f
h.p = i
e.u = d
e.p = l
l.w = f
d.u = c
d.p = l
c.u = d
c.p = b
assert e.p.w.p.w.u.p.w.u.txt == "h"