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

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

l = A("l")
a = B("a")
h = B("h")
d = B("d")
b = A("b")
n = A("n")
e = B("e")
f = A("f")
i = B("i")
m = A("m")

l.r = e
l.o = f
a.x = b
a.p = m
h.x = b
h.p = b
d.x = f
d.p = b
b.r = a
b.o = m
n.r = h
n.o = m
e.x = n
e.p = f
f.r = h
f.o = b
i.x = b
i.p = l
m.r = a
m.o = b
assert d.p.r.p.o.r.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.o: A = None
        self.txt = txt

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

l = A("l")
a = B("a")
h = B("h")
d = B("d")
b = A("b")
n = A("n")
e = B("e")
f = A("f")
i = B("i")
m = A("m")

l.r = e
l.o = f
a.x = b
a.p = m
h.x = b
h.p = b
d.x = f
d.p = b
b.r = a
b.o = m
n.r = h
n.o = m
e.x = n
e.p = f
f.r = h
f.o = b
i.x = b
i.p = l
m.r = a
m.o = b
assert d.p.r.p.o.r.p.o.txt == "b"