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

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

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

l = A("l")
d = B("d")
f = C("f")

l.q = f
l.p = d
d.y = l
f.v = l
assert d.y.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.p: B = None
        self.txt = txt

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

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

l = A("l")
d = B("d")
f = C("f")

l.q = f
l.p = d
d.y = l
f.v = l
assert d.y.q.v.txt == "l"