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

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

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

a = A("a")
i = B("i")
e = C("e")
f = C("f")

a.p = i
a.r = i
i.u = f
e.s = f
e.q = a
e.v = a
f.s = e
f.q = a
f.v = a
assert i.u.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: B = None
        self.txt = txt

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

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

a = A("a")
i = B("i")
e = C("e")
f = C("f")

a.p = i
a.r = i
i.u = f
e.s = f
e.q = a
e.v = a
f.s = e
f.q = a
f.v = a
assert i.u.q.p.txt == "i"