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

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

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

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

l.r = i
f.x = d
f.y = c
f.p = c
i.t = f
i.v = f
i.z = l
c.x = d
c.y = f
c.p = f
d.t = c
d.v = f
d.z = l
assert d.v.x.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

l.r = i
f.x = d
f.y = c
f.p = c
i.t = f
i.v = f
i.z = l
c.x = d
c.y = f
c.p = f
d.t = c
d.v = f
d.z = l
assert d.v.x.v.p.txt == "c"