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

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

d = A("d")
j = B("j")
g = B("g")
m = B("m")
c = A("c")
a = A("a")
l = A("l")
h = B("h")
n = A("n")

d.u = a
d.x = n
j.p = g
j.o = g
g.p = m
g.o = j
m.p = h
m.o = h
c.u = d
c.x = d
a.u = l
a.x = c
l.u = d
l.x = a
h.p = j
h.o = g
n.u = c
n.x = a
assert g.o.o.p.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.x: A = None
        self.txt = txt

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

d = A("d")
j = B("j")
g = B("g")
m = B("m")
c = A("c")
a = A("a")
l = A("l")
h = B("h")
n = A("n")

d.u = a
d.x = n
j.p = g
j.o = g
g.p = m
g.o = j
m.p = h
m.o = h
c.u = d
c.x = d
a.u = l
a.x = c
l.u = d
l.x = a
h.p = j
h.o = g
n.u = c
n.x = a
assert g.o.o.p.o.p.txt == "j"