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

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

d = A("d")
m = B("m")
j = A("j")
f = A("f")
i = A("i")
c = A("c")

d.s = j
d.t = m
m.q = i
m.p = j
j.s = c
j.t = m
f.s = i
f.t = m
i.s = j
i.t = m
c.s = j
c.t = m
assert j.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.t: B = None
        self.txt = txt

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

d = A("d")
m = B("m")
j = A("j")
f = A("f")
i = A("i")
c = A("c")

d.s = j
d.t = m
m.q = i
m.p = j
j.s = c
j.t = m
f.s = i
f.t = m
i.s = j
i.t = m
c.s = j
c.t = m
assert j.s.s.s.s.txt == "j"