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

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

m = A("m")
h = B("h")
i = A("i")
k = B("k")
f = A("f")
j = B("j")
d = B("d")
n = A("n")

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

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

m = A("m")
h = B("h")
i = A("i")
k = B("k")
f = A("f")
j = B("j")
d = B("d")
n = A("n")

m.r = j
m.o = j
h.x = d
i.r = j
i.o = h
k.x = h
f.r = k
f.o = d
j.x = h
d.x = k
n.r = h
n.o = d
assert i.o.x.x.x.x.x.x.txt == "h"