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

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

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

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

e = A("e")
m = B("m")
c = C("c")
f = D("f")
j = D("j")

e.q = m
m.q = c
m.s = j
c.y = e
f.w = e
f.v = j
j.w = e
j.v = f
assert m.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

e = A("e")
m = B("m")
c = C("c")
f = D("f")
j = D("j")

e.q = m
m.q = c
m.s = j
c.y = e
f.w = e
f.v = j
j.w = e
j.v = f
assert m.q.y.q.txt == "m"