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

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

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

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

f.v = a
c.w = e
e.q = c
e.x = c
e.y = m
m.q = c
m.x = c
m.y = e
b.v = f
a.v = b
assert f.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.txt = txt

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

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

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

f.v = a
c.w = e
e.q = c
e.x = c
e.y = m
m.q = c
m.x = c
m.y = e
b.v = f
a.v = b
assert f.v.v.v.v.v.txt == "b"