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

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

m = A("m")
g = B("g")
k = A("k")
i = A("i")
j = B("j")
f = A("f")
c = A("c")
l = A("l")

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

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

m = A("m")
g = B("g")
k = A("k")
i = A("i")
j = B("j")
f = A("f")
c = A("c")
l = A("l")

m.y = j
m.r = k
g.r = c
k.y = j
k.r = c
i.y = j
i.r = f
j.r = l
f.y = g
f.r = k
c.y = j
c.r = m
l.y = j
l.r = c
assert l.r.y.r.y.r.txt == "l"