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

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

j = A("j")
a = B("a")
l = A("l")
i = B("i")
c = A("c")
b = A("b")
g = A("g")
d = B("d")
m = B("m")
e = A("e")

j.y = i
j.r = a
a.r = e
l.y = m
l.r = a
i.r = j
c.y = d
c.r = i
b.y = i
b.r = a
g.y = m
g.r = d
d.r = l
m.r = e
e.y = a
e.r = a
assert l.r.r.y.r.y.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.r: B = None
        self.txt = txt

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

j = A("j")
a = B("a")
l = A("l")
i = B("i")
c = A("c")
b = A("b")
g = A("g")
d = B("d")
m = B("m")
e = A("e")

j.y = i
j.r = a
a.r = e
l.y = m
l.r = a
i.r = j
c.y = d
c.r = i
b.y = i
b.r = a
g.y = m
g.r = d
d.r = l
m.r = e
e.y = a
e.r = a
assert l.r.r.y.r.y.r.y.txt == "a"