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

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

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

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

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

h.y = g
j.t = i
k.p = n
g.z = n
g.q = n
g.x = i
i.y = g
n.t = h
assert k.p.t.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

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

h.y = g
j.t = i
k.p = n
g.z = n
g.q = n
g.x = i
i.y = g
n.t = h
assert k.p.t.y.x.txt == "i"