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

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

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

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

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

g.s = h
g.z = d
b.p = k
b.u = i
b.y = g
i.q = g
d.q = b
d.u = g
h.q = g
k.q = b
k.u = g
assert h.q.z.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.z: D = None
        self.txt = txt

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

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

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

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

g.s = h
g.z = d
b.p = k
b.u = i
b.y = g
i.q = g
d.q = b
d.u = g
h.q = g
k.q = b
k.u = g
assert h.q.z.u.s.txt == "h"