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

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

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

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

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

m.p = a
a.w = m
a.x = h
g.q = h
h.o = g
h.w = m
assert a.x.o.q.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

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

m.p = a
a.w = m
a.x = h
g.q = h
h.o = g
h.w = m
assert a.x.o.q.o.txt == "g"