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

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

f = A("f")
j = B("j")
b = A("b")
k = A("k")
d = B("d")
c = A("c")
m = B("m")
i = A("i")
e = B("e")
h = A("h")

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

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

f = A("f")
j = B("j")
b = A("b")
k = A("k")
d = B("d")
c = A("c")
m = B("m")
i = A("i")
e = B("e")
h = A("h")

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