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

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

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

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

d = A("d")
f = B("f")
g = C("g")
m = D("m")
a = D("a")

d.r = f
f.r = d
f.p = d
f.q = g
f.v = g
g.w = f
g.u = d
g.r = a
m.o = d
m.w = a
m.p = g
m.t = f
a.o = d
a.w = m
a.p = g
a.t = f
assert a.w.o.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

d = A("d")
f = B("f")
g = C("g")
m = D("m")
a = D("a")

d.r = f
f.r = d
f.p = d
f.q = g
f.v = g
g.w = f
g.u = d
g.r = a
m.o = d
m.w = a
m.p = g
m.t = f
a.o = d
a.w = m
a.p = g
a.t = f
assert a.w.o.r.q.txt == "g"