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

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

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

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

g = A("g")
f = B("f")
h = C("h")
b = D("b")
j = D("j")
n = C("n")
k = B("k")

g.s = j
f.q = k
f.y = j
h.q = b
h.s = f
h.w = g
b.t = n
j.t = n
n.q = b
n.s = k
n.w = g
k.q = f
k.y = b
assert g.s.t.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

g = A("g")
f = B("f")
h = C("h")
b = D("b")
j = D("j")
n = C("n")
k = B("k")

g.s = j
f.q = k
f.y = j
h.q = b
h.s = f
h.w = g
b.t = n
j.t = n
n.q = b
n.s = k
n.w = g
k.q = f
k.y = b
assert g.s.t.s.txt == "k"