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

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

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

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

d = A("d")
m = B("m")
i = C("i")
f = D("f")
b = A("b")
l = D("l")

d.x = i
m.s = i
m.w = i
i.w = d
i.y = d
i.t = d
i.s = l
f.q = l
b.x = i
l.q = f
assert i.w.x.s.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

d = A("d")
m = B("m")
i = C("i")
f = D("f")
b = A("b")
l = D("l")

d.x = i
m.s = i
m.w = i
i.w = d
i.y = d
i.t = d
i.s = l
f.q = l
b.x = i
l.q = f
assert i.w.x.s.q.q.q.txt == "f"