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

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

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

class D:
    def __init__(self, txt: str):
        self.o: B = None
        self.u: C = None
        self.v: C = None
        self.txt = txt

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

l.w = d
h.s = g
h.t = l
h.x = l
h.y = d
d.q = l
d.v = h
g.o = h
g.u = d
g.v = d
assert d.q.w.q.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.o: B = None
        self.u: C = None
        self.v: C = None
        self.txt = txt

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

l.w = d
h.s = g
h.t = l
h.x = l
h.y = d
d.q = l
d.v = h
g.o = h
g.u = d
g.v = d
assert d.q.w.q.w.txt == "d"