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

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

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

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

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

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

a.x = b
a.r = g
h.o = i
h.y = b
g.x = d
g.r = b
i.o = h
i.y = a
m.o = h
m.y = d
j.o = m
j.y = n
b.x = n
b.r = a
d.x = a
d.r = a
n.x = g
n.r = a
assert i.o.y.x.r.txt == "a"