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

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

d = A("d")
h = B("h")
k = A("k")
g = B("g")
b = B("b")

d.s = g
d.t = h
h.o = k
h.p = k
k.s = b
k.t = b
g.o = k
g.p = k
b.o = d
b.p = d
assert k.s.p.t.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.t: B = None
        self.txt = txt

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

d = A("d")
h = B("h")
k = A("k")
g = B("g")
b = B("b")

d.s = g
d.t = h
h.o = k
h.p = k
k.s = b
k.t = b
g.o = k
g.p = k
b.o = d
b.p = d
assert k.s.p.t.p.t.txt == "b"