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

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

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

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

n = A("n")
h = B("h")
d = C("d")
g = D("g")
i = A("i")

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

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

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

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

n = A("n")
h = B("h")
d = C("d")
g = D("g")
i = A("i")

n.t = h
n.q = h
h.y = n
d.q = n
d.z = g
d.s = h
g.r = h
g.p = h
i.t = h
i.q = h
assert i.t.y.q.txt == "h"