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

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

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

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

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

m.y = j
m.w = j
m.r = h
j.y = m
h.o = m
h.x = m
h.q = j
b.s = h
b.t = h
b.y = h
assert b.t.x.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.r: C = None
        self.w: B = None
        self.txt = txt

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

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

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

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

m.y = j
m.w = j
m.r = h
j.y = m
h.o = m
h.x = m
h.q = j
b.s = h
b.t = h
b.y = h
assert b.t.x.y.y.txt == "m"