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

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

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

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

c = A("c")
b = B("b")
g = C("g")
k = D("k")

c.y = b
b.v = c
b.q = g
g.q = b
g.t = c
k.v = b
k.y = b
k.t = b
k.p = g
assert c.y.v.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

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

c = A("c")
b = B("b")
g = C("g")
k = D("k")

c.y = b
b.v = c
b.q = g
g.q = b
g.t = c
k.v = b
k.y = b
k.t = b
k.p = g
assert c.y.v.y.v.txt == "c"