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

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

k = A("k")
j = B("j")
l = B("l")
f = A("f")
d = A("d")

k.o = l
j.s = l
j.p = d
l.s = j
l.p = d
f.o = j
d.o = j
assert d.o.p.o.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

k = A("k")
j = B("j")
l = B("l")
f = A("f")
d = A("d")

k.o = l
j.s = l
j.p = d
l.s = j
l.p = d
f.o = j
d.o = j
assert d.o.p.o.p.o.txt == "j"