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

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

k = A("k")
d = B("d")
f = A("f")
h = A("h")
c = B("c")
n = A("n")
g = A("g")

k.t = c
d.y = g
d.z = c
f.t = c
h.t = c
c.y = g
c.z = d
n.t = c
g.t = c
assert n.t.z.y.t.y.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

k = A("k")
d = B("d")
f = A("f")
h = A("h")
c = B("c")
n = A("n")
g = A("g")

k.t = c
d.y = g
d.z = c
f.t = c
h.t = c
c.y = g
c.z = d
n.t = c
g.t = c
assert n.t.z.y.t.y.t.z.txt == "d"