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

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

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

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

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

a.y = m
a.t = m
n.q = g
n.t = c
n.p = a
g.t = m
g.s = n
g.q = a
g.z = b
m.y = n
c.y = m
c.t = b
b.y = n
assert m.y.q.z.y.t.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.t: D = None
        self.txt = txt

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

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

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

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

a.y = m
a.t = m
n.q = g
n.t = c
n.p = a
g.t = m
g.s = n
g.q = a
g.z = b
m.y = n
c.y = m
c.t = b
b.y = n
assert m.y.q.z.y.t.txt == "c"