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

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

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

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

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

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

b.y = n
b.x = j
i.r = c
a.r = g
n.y = c
n.x = i
j.r = n
c.y = n
c.x = i
f.y = b
f.x = i
k.r = b
m.r = g
g.y = n
g.x = k
assert m.r.y.y.x.r.y.x.txt == "i"