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

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

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

k = A("k")
d = B("d")
g = C("g")
n = A("n")

k.q = d
k.s = d
k.v = n
d.v = g
g.p = k
g.r = d
n.q = d
n.s = d
n.v = k
assert g.p.v.q.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: B = None
        self.v: A = None
        self.txt = txt

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

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

k = A("k")
d = B("d")
g = C("g")
n = A("n")

k.q = d
k.s = d
k.v = n
d.v = g
g.p = k
g.r = d
n.q = d
n.s = d
n.v = k
assert g.p.v.q.v.txt == "g"