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

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

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

j = A("j")
c = B("c")
f = C("f")

j.t = c
j.r = f
c.q = f
c.v = j
c.r = j
f.v = c
f.s = c
assert c.q.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: C = None
        self.txt = txt

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

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

j = A("j")
c = B("c")
f = C("f")

j.t = c
j.r = f
c.q = f
c.v = j
c.r = j
f.v = c
f.s = c
assert c.q.s.r.txt == "j"