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

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

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

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

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

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

l.r = i
j.w = i
d.r = l
a.r = i
b.r = i
c.w = i
i.r = l
assert i.r.r.r.r.r.r.r.txt == "l"