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.v: A = None
        self.q: B = None
        self.txt = txt

d = A("d")
i = B("i")
b = A("b")
m = A("m")
f = B("f")
c = A("c")
e = A("e")

d.t = e
d.w = i
i.v = d
i.q = f
b.t = d
b.w = f
m.t = d
m.w = f
f.v = c
f.q = i
c.t = b
c.w = f
e.t = c
e.w = f
assert d.t.t.t.t.t.t.w.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.v: A = None
        self.q: B = None
        self.txt = txt

d = A("d")
i = B("i")
b = A("b")
m = A("m")
f = B("f")
c = A("c")
e = A("e")

d.t = e
d.w = i
i.v = d
i.q = f
b.t = d
b.w = f
m.t = d
m.w = f
f.v = c
f.q = i
c.t = b
c.w = f
e.t = c
e.w = f
assert d.t.t.t.t.t.t.w.txt == "f"