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

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

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

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

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

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

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

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

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

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

l.q = d
l.s = d
m.t = g
d.y = l
d.x = l
d.s = m
d.t = m
g.z = l
assert d.y.q.x.txt == "l"