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

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

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

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

g = A("g")
k = B("k")
n = C("n")
b = D("b")
i = B("i")

g.w = i
k.o = b
k.r = g
k.w = g
k.y = i
n.q = b
n.t = g
n.o = g
n.p = i
b.u = g
b.y = g
b.x = k
i.o = b
i.r = g
i.w = g
i.y = k
assert k.r.w.o.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

g = A("g")
k = B("k")
n = C("n")
b = D("b")
i = B("i")

g.w = i
k.o = b
k.r = g
k.w = g
k.y = i
n.q = b
n.t = g
n.o = g
n.p = i
b.u = g
b.y = g
b.x = k
i.o = b
i.r = g
i.w = g
i.y = k
assert k.r.w.o.x.r.txt == "g"