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

class B:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

k = A("k")
c = B("c")
m = C("m")
j = D("j")

k.x = c
k.y = j
c.v = j
m.y = c
j.v = k
j.q = k
assert k.x.v.v.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.y: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.v: D = None
        self.txt = txt

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

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

k = A("k")
c = B("c")
m = C("m")
j = D("j")

k.x = c
k.y = j
c.v = j
m.y = c
j.v = k
j.q = k
assert k.x.v.v.x.txt == "c"