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

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

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

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

a = A("a")
h = B("h")
d = C("d")
k = D("k")

a.w = d
a.r = h
a.t = h
h.q = k
h.w = k
h.p = a
h.x = a
d.p = a
d.w = h
k.y = a
k.t = h
k.r = h
assert a.w.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: B = None
        self.t: B = None
        self.txt = txt

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

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

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

a = A("a")
h = B("h")
d = C("d")
k = D("k")

a.w = d
a.r = h
a.t = h
h.q = k
h.w = k
h.p = a
h.x = a
d.p = a
d.w = h
k.y = a
k.t = h
k.r = h
assert a.w.p.t.txt == "h"