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

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

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

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

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

g.q = k
g.t = j
g.y = j
k.v = g
k.s = g
f.o = j
f.s = g
f.w = g
j.w = k
j.r = f
assert f.w.t.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: D = None
        self.y: D = None
        self.txt = txt

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

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

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

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

g.q = k
g.t = j
g.y = j
k.v = g
k.s = g
f.o = j
f.s = g
f.w = g
j.w = k
j.r = f
assert f.w.t.r.w.txt == "g"