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

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

b = A("b")
h = B("h")
n = B("n")
m = A("m")
j = A("j")
g = B("g")
d = A("d")
i = B("i")

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

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

b = A("b")
h = B("h")
n = B("n")
m = A("m")
j = A("j")
g = B("g")
d = A("d")
i = B("i")

b.u = j
h.p = n
h.o = j
n.p = i
n.o = d
m.u = d
j.u = d
g.p = i
g.o = b
d.u = b
i.p = h
i.o = j
assert h.o.u.u.u.u.u.u.u.txt == "d"