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

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

h = A("h")
l = B("l")
k = A("k")
n = B("n")
d = A("d")
f = A("f")

h.x = n
h.p = l
l.u = f
l.w = h
k.x = l
k.p = n
n.u = f
n.w = h
d.x = l
d.p = l
f.x = l
f.p = l
assert h.x.w.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.p: B = None
        self.txt = txt

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

h = A("h")
l = B("l")
k = A("k")
n = B("n")
d = A("d")
f = A("f")

h.x = n
h.p = l
l.u = f
l.w = h
k.x = l
k.p = n
n.u = f
n.w = h
d.x = l
d.p = l
f.x = l
f.p = l
assert h.x.w.x.w.txt == "h"