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

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

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

a = A("a")
l = B("l")
f = C("f")
c = A("c")
e = A("e")
d = B("d")
b = A("b")
m = C("m")

a.r = b
l.v = b
l.u = f
f.w = l
f.q = l
c.r = e
e.r = a
d.v = e
d.u = f
b.r = c
m.w = d
m.q = d
assert a.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.v: A = None
        self.u: C = None
        self.txt = txt

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

a = A("a")
l = B("l")
f = C("f")
c = A("c")
e = A("e")
d = B("d")
b = A("b")
m = C("m")

a.r = b
l.v = b
l.u = f
f.w = l
f.q = l
c.r = e
e.r = a
d.v = e
d.u = f
b.r = c
m.w = d
m.q = d
assert a.r.r.r.txt == "e"