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

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

h = A("h")
i = B("i")
m = A("m")
g = B("g")
d = B("d")
a = A("a")
k = B("k")
e = B("e")
c = A("c")
j = B("j")

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

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

h = A("h")
i = B("i")
m = A("m")
g = B("g")
d = B("d")
a = A("a")
k = B("k")
e = B("e")
c = A("c")
j = B("j")

h.p = d
h.u = m
i.w = d
m.p = g
m.u = c
g.w = e
d.w = e
a.p = k
a.u = m
k.w = j
e.w = j
c.p = d
c.u = h
j.w = e
assert c.p.w.w.txt == "j"