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

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

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

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

h = A("h")
g = B("g")
c = C("c")
b = D("b")
e = A("e")

h.w = e
h.s = e
h.r = g
g.q = b
c.y = b
b.t = g
e.w = h
e.s = h
e.r = g
assert h.r.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.r: B = None
        self.s: A = None
        self.txt = txt

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

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

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

h = A("h")
g = B("g")
c = C("c")
b = D("b")
e = A("e")

h.w = e
h.s = e
h.r = g
g.q = b
c.y = b
b.t = g
e.w = h
e.s = h
e.r = g
assert h.r.q.t.txt == "g"