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

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

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

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

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

l.t = g
g.w = l
g.t = m
a.o = g
m.z = g
m.t = l
m.w = l
assert g.w.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

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

l.t = g
g.w = l
g.t = m
a.o = g
m.z = g
m.t = l
m.w = l
assert g.w.t.t.txt == "m"