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

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

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

c = A("c")
f = B("f")
i = C("i")
l = A("l")

c.v = f
c.u = f
c.x = l
f.r = i
f.p = c
i.v = f
i.r = f
i.u = l
l.v = f
l.u = f
l.x = c
assert l.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.u: B = None
        self.x: A = None
        self.txt = txt

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

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

c = A("c")
f = B("f")
i = C("i")
l = A("l")

c.v = f
c.u = f
c.x = l
f.r = i
f.p = c
i.v = f
i.r = f
i.u = l
l.v = f
l.u = f
l.x = c
assert l.x.x.x.txt == "c"