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

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

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

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

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

h.r = n
j.t = b
j.w = n
j.o = n
n.q = h
n.v = j
n.w = j
b.r = n
b.z = n
b.s = h
b.w = j
assert n.w.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

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

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

h.r = n
j.t = b
j.w = n
j.o = n
n.q = h
n.v = j
n.w = j
b.r = n
b.z = n
b.s = h
b.w = j
assert n.w.o.q.txt == "h"