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

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

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

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

e = A("e")
g = B("g")
f = C("f")
m = D("m")

e.t = g
g.q = m
g.t = e
g.x = e
f.x = m
m.s = e
m.o = e
assert g.x.t.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.q: D = None
        self.t: A = None
        self.x: A = None
        self.txt = txt

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

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

e = A("e")
g = B("g")
f = C("f")
m = D("m")

e.t = g
g.q = m
g.t = e
g.x = e
f.x = m
m.s = e
m.o = e
assert g.x.t.t.t.txt == "g"