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

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

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

h = A("h")
g = B("g")
d = C("d")
f = B("f")

h.v = d
h.s = d
g.u = d
g.q = d
g.v = h
d.z = h
f.u = d
f.q = d
f.v = h
assert f.u.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.s: C = None
        self.txt = txt

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

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

h = A("h")
g = B("g")
d = C("d")
f = B("f")

h.v = d
h.s = d
g.u = d
g.q = d
g.v = h
d.z = h
f.u = d
f.q = d
f.v = h
assert f.u.z.s.txt == "d"