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

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

i = A("i")
k = B("k")
d = A("d")
c = A("c")
e = B("e")

i.t = c
i.w = k
k.x = d
d.t = c
d.w = k
c.t = i
c.w = k
e.x = c
assert k.x.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.w: B = None
        self.txt = txt

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

i = A("i")
k = B("k")
d = A("d")
c = A("c")
e = B("e")

i.t = c
i.w = k
k.x = d
d.t = c
d.w = k
c.t = i
c.w = k
e.x = c
assert k.x.w.x.txt == "d"