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

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

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

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

j = A("j")
d = B("d")
g = C("g")
h = D("h")

j.y = h
d.x = g
d.w = g
g.w = j
g.q = h
h.q = g
assert d.x.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: D = None
        self.txt = txt

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

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

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

j = A("j")
d = B("d")
g = C("g")
h = D("h")

j.y = h
d.x = g
d.w = g
g.w = j
g.q = h
h.q = g
assert d.x.w.y.txt == "h"