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

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

h = A("h")
m = B("m")
d = A("d")
n = A("n")
b = B("b")
e = A("e")

h.u = b
h.x = d
m.p = n
m.s = b
d.u = b
d.x = e
n.u = m
n.x = d
b.p = h
b.s = m
e.u = b
e.x = d
assert b.s.p.x.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.x: A = None
        self.txt = txt

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

h = A("h")
m = B("m")
d = A("d")
n = A("n")
b = B("b")
e = A("e")

h.u = b
h.x = d
m.p = n
m.s = b
d.u = b
d.x = e
n.u = m
n.x = d
b.p = h
b.s = m
e.u = b
e.x = d
assert b.s.p.x.x.u.txt == "b"