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

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

d = A("d")
f = B("f")
a = A("a")
j = B("j")
m = A("m")
h = B("h")
b = A("b")
c = B("c")
n = A("n")
i = B("i")

d.x = h
f.p = b
f.u = b
a.x = j
j.p = a
j.u = d
m.x = h
h.p = a
h.u = b
b.x = h
c.p = d
c.u = d
n.x = h
i.p = m
i.u = d
assert a.x.p.x.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

d = A("d")
f = B("f")
a = A("a")
j = B("j")
m = A("m")
h = B("h")
b = A("b")
c = B("c")
n = A("n")
i = B("i")

d.x = h
f.p = b
f.u = b
a.x = j
j.p = a
j.u = d
m.x = h
h.p = a
h.u = b
b.x = h
c.p = d
c.u = d
n.x = h
i.p = m
i.u = d
assert a.x.p.x.u.x.txt == "h"