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

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

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

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

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

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

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

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

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

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

n.s = d
n.w = m
k.t = d
m.q = n
g.q = n
g.v = k
g.t = k
j.q = n
j.v = d
j.t = k
d.t = k
assert k.t.t.t.txt == "d"