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

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

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

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

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

a.x = g
e.o = g
e.t = j
e.y = j
b.t = e
j.o = e
j.x = a
g.x = a
assert b.t.o.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

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

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

a.x = g
e.o = g
e.t = j
e.y = j
b.t = e
j.o = e
j.x = a
g.x = a
assert b.t.o.x.x.x.txt == "a"