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

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

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

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

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

g.r = m
g.z = h
g.x = k
m.s = k
m.q = k
m.p = a
k.s = m
i.y = m
i.t = k
h.y = m
h.t = k
a.r = m
a.z = i
a.x = k
assert g.x.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.z: D = None
        self.x: C = None
        self.txt = txt

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

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

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

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

g.r = m
g.z = h
g.x = k
m.s = k
m.q = k
m.p = a
k.s = m
i.y = m
i.t = k
h.y = m
h.t = k
a.r = m
a.z = i
a.x = k
assert g.x.s.q.txt == "k"