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

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

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

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

h = A("h")
g = B("g")
n = C("n")
i = D("i")
c = B("c")
a = C("a")
m = A("m")

h.t = m
h.x = m
h.z = a
g.z = n
g.q = n
g.t = i
n.y = i
i.x = c
c.z = a
c.q = a
c.t = i
a.y = i
m.t = h
m.x = h
m.z = a
assert a.y.x.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.z: C = None
        self.x: A = None
        self.txt = txt

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

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

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

h = A("h")
g = B("g")
n = C("n")
i = D("i")
c = B("c")
a = C("a")
m = A("m")

h.t = m
h.x = m
h.z = a
g.z = n
g.q = n
g.t = i
n.y = i
i.x = c
c.z = a
c.q = a
c.t = i
a.y = i
m.t = h
m.x = h
m.z = a
assert a.y.x.t.x.txt == "c"