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

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

j = A("j")
f = B("f")
n = B("n")
b = B("b")
g = B("g")
c = A("c")
k = B("k")
m = A("m")

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

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

j = A("j")
f = B("f")
n = B("n")
b = B("b")
g = B("g")
c = A("c")
k = B("k")
m = A("m")

j.u = n
f.o = j
f.x = c
n.o = c
n.x = c
b.o = c
b.x = c
g.o = m
g.x = c
c.u = k
k.o = j
k.x = j
m.u = b
assert m.u.x.u.x.u.x.txt == "c"