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

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

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

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

i = A("i")
e = B("e")
j = C("j")
c = D("c")

i.t = e
e.q = j
e.x = j
j.r = i
c.y = i
assert c.y.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

i = A("i")
e = B("e")
j = C("j")
c = D("c")

i.t = e
e.q = j
e.x = j
j.r = i
c.y = i
assert c.y.t.x.txt == "j"