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

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

class C:
    def __init__(self, txt: str):
        self.t: C = None
        self.y: C = None
        self.txt = txt

j = A("j")
b = B("b")
f = C("f")
d = C("d")
a = B("a")
g = A("g")
h = C("h")

j.z = g
b.q = h
b.r = a
b.v = g
f.t = d
f.y = h
d.t = h
d.y = h
a.q = f
a.r = b
a.v = j
g.z = j
h.t = f
h.y = d
assert g.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.t: C = None
        self.y: C = None
        self.txt = txt

j = A("j")
b = B("b")
f = C("f")
d = C("d")
a = B("a")
g = A("g")
h = C("h")

j.z = g
b.q = h
b.r = a
b.v = g
f.t = d
f.y = h
d.t = h
d.y = h
a.q = f
a.r = b
a.v = j
g.z = j
h.t = f
h.y = d
assert g.z.z.z.z.z.z.txt == "g"