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

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

h = A("h")
f = B("f")
a = A("a")
d = B("d")
k = B("k")
b = B("b")
n = A("n")
m = A("m")

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

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

h = A("h")
f = B("f")
a = A("a")
d = B("d")
k = B("k")
b = B("b")
n = A("n")
m = A("m")

h.o = d
f.x = b
f.u = n
a.o = d
d.x = k
d.u = m
k.x = f
k.u = a
b.x = d
b.u = h
n.o = b
m.o = f
assert f.x.u.o.u.o.u.o.txt == "b"