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

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

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

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

f = A("f")
l = B("l")
m = C("m")
g = D("g")
e = B("e")
b = A("b")

f.v = b
l.v = e
m.v = l
m.s = f
g.w = b
g.q = b
g.s = m
e.v = l
b.v = f
assert f.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.v: B = None
        self.txt = txt

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

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

f = A("f")
l = B("l")
m = C("m")
g = D("g")
e = B("e")
b = A("b")

f.v = b
l.v = e
m.v = l
m.s = f
g.w = b
g.q = b
g.s = m
e.v = l
b.v = f
assert f.v.v.v.txt == "b"