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

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

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

h = A("h")
l = B("l")
m = C("m")
d = C("d")
g = A("g")

h.z = g
h.t = l
l.t = d
l.x = d
m.u = l
m.q = g
d.u = l
d.q = g
g.z = h
g.t = l
assert l.x.u.x.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.t: B = None
        self.txt = txt

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

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

h = A("h")
l = B("l")
m = C("m")
d = C("d")
g = A("g")

h.z = g
h.t = l
l.t = d
l.x = d
m.u = l
m.q = g
d.u = l
d.q = g
g.z = h
g.t = l
assert l.x.u.x.q.z.txt == "h"