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

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

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

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

k = A("k")
e = B("e")
f = C("f")
a = D("a")
h = B("h")
j = D("j")
m = C("m")

k.q = f
k.p = f
e.z = h
e.t = h
f.q = k
f.w = k
a.s = k
a.q = k
a.r = h
h.z = e
h.t = e
j.s = k
j.q = k
j.r = e
m.q = k
m.w = k
assert f.w.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.p: C = None
        self.txt = txt

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

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

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

k = A("k")
e = B("e")
f = C("f")
a = D("a")
h = B("h")
j = D("j")
m = C("m")

k.q = f
k.p = f
e.z = h
e.t = h
f.q = k
f.w = k
a.s = k
a.q = k
a.r = h
h.z = e
h.t = e
j.s = k
j.q = k
j.r = e
m.q = k
m.w = k
assert f.w.q.w.txt == "k"