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

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

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

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

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

b.w = e
b.y = e
b.q = i
b.r = i
c.y = b
c.r = b
c.w = d
i.p = d
d.x = e
e.y = b
e.r = b
e.w = d
h.w = c
h.y = c
h.q = i
h.r = i
assert h.q.p.x.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.q: C = None
        self.y: B = None
        self.r: C = None
        self.txt = txt

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

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

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

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

b.w = e
b.y = e
b.q = i
b.r = i
c.y = b
c.r = b
c.w = d
i.p = d
d.x = e
e.y = b
e.r = b
e.w = d
h.w = c
h.y = c
h.q = i
h.r = i
assert h.q.p.x.y.w.txt == "e"