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

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

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

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

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

h.y = e
h.o = g
a.p = m
a.y = e
a.u = b
a.w = b
e.q = b
m.r = a
g.r = a
b.y = e
b.o = m
assert e.q.o.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.o: D = None
        self.txt = txt

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

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

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

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

h.y = e
h.o = g
a.p = m
a.y = e
a.u = b
a.w = b
e.q = b
m.r = a
g.r = a
b.y = e
b.o = m
assert e.q.o.r.w.txt == "b"