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

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

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

l.r = k
j.x = k
j.u = l
m.x = l
m.u = i
f.x = l
f.u = k
k.r = i
i.r = l
assert i.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.x: A = None
        self.u: A = None
        self.txt = txt

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

l.r = k
j.x = k
j.u = l
m.x = l
m.u = i
f.x = l
f.u = k
k.r = i
i.r = l
assert i.r.r.r.r.r.txt == "k"