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

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

i = A("i")
m = B("m")
l = B("l")
n = A("n")
k = B("k")
g = B("g")
b = B("b")
j = B("j")
c = A("c")
d = B("d")

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

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

i = A("i")
m = B("m")
l = B("l")
n = A("n")
k = B("k")
g = B("g")
b = B("b")
j = B("j")
c = A("c")
d = B("d")

i.s = l
m.y = c
l.y = i
n.s = b
k.y = n
g.y = c
b.y = i
j.y = n
c.s = j
d.y = c
assert c.s.y.s.y.s.y.s.y.txt == "i"