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

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

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

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

h = A("h")
b = B("b")
m = C("m")
n = D("n")
g = A("g")

h.r = g
h.p = g
h.o = m
b.z = m
b.x = g
m.q = n
m.o = n
m.w = n
n.u = b
g.r = h
g.p = h
g.o = m
assert n.u.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.o: C = None
        self.p: A = None
        self.txt = txt

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

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

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

h = A("h")
b = B("b")
m = C("m")
n = D("n")
g = A("g")

h.r = g
h.p = g
h.o = m
b.z = m
b.x = g
m.q = n
m.o = n
m.w = n
n.u = b
g.r = h
g.p = h
g.o = m
assert n.u.z.o.txt == "n"