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

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

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

g = A("g")
d = B("d")
h = C("h")
i = A("i")
c = C("c")

g.r = i
g.q = i
g.t = d
d.z = h
h.s = i
i.r = g
i.q = g
i.t = d
c.s = i
assert d.z.s.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: B = None
        self.q: A = None
        self.txt = txt

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

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

g = A("g")
d = B("d")
h = C("h")
i = A("i")
c = C("c")

g.r = i
g.q = i
g.t = d
d.z = h
h.s = i
i.r = g
i.q = g
i.t = d
c.s = i
assert d.z.s.t.z.txt == "h"