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

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

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

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

j = A("j")
k = B("k")
b = C("b")
d = D("d")
g = D("g")

j.q = k
k.w = b
k.u = d
b.q = j
b.t = j
d.t = j
d.v = k
g.t = j
g.v = k
assert b.t.q.w.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

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

j = A("j")
k = B("k")
b = C("b")
d = D("d")
g = D("g")

j.q = k
k.w = b
k.u = d
b.q = j
b.t = j
d.t = j
d.v = k
g.t = j
g.v = k
assert b.t.q.w.q.q.txt == "k"